Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lava_labs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
misury
lava_labs
Merge requests
!2
Laba2
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Laba2
laba2
into
main
Overview
0
Commits
2
Pipelines
0
Changes
1
Open
misury
requested to merge
laba2
into
main
2 weeks ago
Overview
0
Commits
2
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
095ee5ca
2 commits,
2 weeks ago
1 file
+
77
−
20
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Conflict: This file was modified in both the source and target branches. Ask someone with write access to resolve it.
src/Main.java
+
77
−
20
Options
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
import
java.util.Scanner
;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
int
height
=
100
;
int
width
=
100
;
int
All
=
height
*
width
;
double
step
=
Math
.
PI
/
(
All
-
1
);
double
[][]
table
=
new
double
[
height
][
width
];
double
[][]
table_x
=
new
double
[
height
][
width
];
double
x
=
-
step
;
for
(
int
i
=
0
;
i
<
width
;
i
++)
{
for
(
int
j
=
0
;
j
<
height
;
j
++)
{
x
+=
step
;
table_x
[
j
][
i
]
=
x
;
table
[
j
][
i
]
=
Math
.
abs
(
Math
.
sin
(
x
));
Scanner
scanner
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"Введите коэффициенты a, b, c: "
);
double
a
=
scanner
.
nextDouble
();
double
b
=
scanner
.
nextDouble
();
double
c
=
scanner
.
nextDouble
();
System
.
out
.
print
(
"Введите границы интервала от и до: "
);
double
xfrom
=
scanner
.
nextDouble
();
double
xto
=
scanner
.
nextDouble
();
System
.
out
.
print
(
"Введите размер таблицы: "
);
int
tableSize
=
scanner
.
nextInt
();
System
.
out
.
print
(
"Введите число разбиений отрезка: "
);
int
stepsCount
=
scanner
.
nextInt
();
scanner
.
close
();
String
[][]
table
=
buildTable
(
a
,
b
,
c
,
xfrom
,
xto
,
tableSize
,
stepsCount
);
printTable
(
table
);
}
public
static
double
f
(
double
a
,
double
b
,
double
c
,
double
x
)
{
return
a
*
x
*
x
+
b
*
x
+
c
;
}
public
static
double
integral
(
double
a
,
double
b
,
double
c
,
double
x0
,
double
x1
,
int
steps
)
{
if
(
x0
>
x1
)
return
-
integral
(
a
,
b
,
c
,
x1
,
x0
,
steps
);
double
n
=
(
x1
-
x0
)
/
steps
;
double
sum
=
(
f
(
a
,
b
,
c
,
x0
)
+
f
(
a
,
b
,
c
,
x1
));
for
(
int
i
=
1
;
i
<
steps
;
i
++)
{
double
xi
=
x0
+
i
*
n
;
sum
+=
2
*
f
(
a
,
b
,
c
,
xi
);
}
return
sum
*
n
/
2
;
}
public
static
String
[][]
buildTable
(
double
a
,
double
b
,
double
c
,
double
xfrom
,
double
xto
,
int
tableSize
,
int
stepsCount
)
{
String
[][]
table
=
new
String
[
tableSize
+
1
][
tableSize
+
1
];
double
[]
xValues
=
new
double
[
tableSize
];
double
step
=
(
xto
-
xfrom
)
/
(
tableSize
-
1
);
for
(
int
i
=
0
;
i
<
tableSize
;
i
++)
{
xValues
[
i
]
=
xfrom
+
i
*
step
;
table
[
0
][
i
+
1
]
=
String
.
format
(
"%.4f"
,
xValues
[
i
]);
table
[
i
+
1
][
0
]
=
String
.
format
(
"%.4f"
,
xValues
[
i
]);
}
table
[
0
][
0
]
=
" "
;
for
(
int
i
=
1
;
i
<
tableSize
+
1
;
i
++)
{
for
(
int
j
=
1
;
j
<
tableSize
+
1
;
j
++)
{
double
x0
=
xValues
[
i
-
1
];
double
x1
=
xValues
[
j
-
1
];
table
[
i
][
j
]
=
String
.
format
(
"%.4f"
,
integral
(
a
,
b
,
c
,
x0
,
x1
,
stepsCount
));
}
}
return
table
;
}
for
(
int
i
=
0
;
i
<
height
;
i
++)
{
for
(
int
j
=
0
;
j
<
width
;
j
++)
{
double
orig
=
Math
.
asin
(
table
[
i
][
j
]);
System
.
out
.
printf
(
"sin(%.4f)=%.4f "
,
table_x
[
i
][
j
],
table
[
i
][
j
]);
public
static
void
printTable
(
String
[][]
table
)
{
int
cnt
=
0
;
for
(
String
[]
row
:
table
)
{
String
row1
=
row
[
0
];
System
.
out
.
printf
(
"%10s |"
,
row1
);
for
(
int
i
=
1
;
i
<
row
.
length
;
i
++)
{
String
cell
=
row
[
i
];
System
.
out
.
printf
(
"%10s"
,
cell
);
}
System
.
out
.
println
();
cnt
+=
1
;
if
(
cnt
<
row
.
length
)
{
System
.
out
.
print
(
"-----------|"
);
for
(
int
i
=
1
;
i
<
row
.
length
;
i
++)
{
System
.
out
.
print
(
"----------"
);
}
System
.
out
.
println
();
}
}
}
}
\ No newline at end of file
Loading