
Сообщение от Coffeini
NeLonS, русский не разумеете?
Ну вот оба описанных способа:
1
| Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
| import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextPane;
import java.awt.Color;
import java.awt.SystemColor;
import javax.swing.JTextField;
public class Main extends JFrame {
static int lengthBad = 2;
static int countBad = 0;
private final JTextPane labelCord;
public static double LengthLine(double x1, double y1, double x2, double y2) {
return Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2));
}
public void mathResult() {
double[][] coord = {
{4.2, 4.6},
{4, 5},
{5.1, 7.4},
{2.1, 4},
{4.7, 4.4},
{4.8, 4.8},
{4.3, 5.3},
{5, 5.4},
{6.5, 8}
};
int count = coord.length;
//poisk centr tag
double cgX = 0;
double cgY = 0;
for (int i = 0; i < count; i++) {
cgX += coord[i][0];
cgY += coord[i][1];
}
cgX /= count;
cgY /= count;
double length[] = new double[count]; // Инициализация массива
for (int i = 0; i < count; i++) {
length[i] = LengthLine(coord[i][0], coord[i][1], cgX, cgY);
if (length[i] > lengthBad) {
countBad += 1;
}
}
double result = ((double) countBad / count) * 100;
String cords = "";
String len = "";
for (int zxc = 0; zxc < count; zxc++) {
for (int n = 0; n < 2; n++) {
cords += coord[zxc][n] + " ";
}
cords += "\n";
len += length[zxc] + "\n";
}
System.out.println(cords);
System.out.println(len);
labelCord.setText(cords);
}
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main frame = new Main();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Main() {
setResizable(false);
setAlwaysOnTop(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 500, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("Координаты пробоин");
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel.setBounds(10, 11, 144, 33);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Расстояния");
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_1.setBounds(186, 11, 89, 33);
contentPane.add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("Критерии отбраковки");
lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_2.setBounds(318, 11, 156, 33);
contentPane.add(lblNewLabel_2);
JLabel lblNewLabel_3 = new JLabel("Результат");
lblNewLabel_3.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_3.setBounds(318, 132, 144, 33);
contentPane.add(lblNewLabel_3);
JTextPane labelCord = new JTextPane();
labelCord.setText("");
labelCord.setBackground(new Color(240, 240, 240));
labelCord.setBounds(10, 65, 144, 185);
contentPane.add(labelCord);
this.labelCord = labelCord;
JTextPane labelLength = new JTextPane();
labelLength.setBackground(SystemColor.menu);
labelLength.setBounds(164, 65, 144, 185);
contentPane.add(labelLength);
JTextPane labelCriteria = new JTextPane();
labelCriteria.setBackground(SystemColor.menu);
labelCriteria.setBounds(318, 54, 144, 56);
contentPane.add(labelCriteria);
JTextPane labelResult = new JTextPane();
labelResult.setBackground(SystemColor.menu);
labelResult.setBounds(318, 176, 144, 56);
contentPane.add(labelResult);
mathResult();
}
} |
|
2
| Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
| import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextPane;
import java.awt.Color;
import java.awt.SystemColor;
import javax.swing.JTextField;
public class Main extends JFrame {
static int lengthBad = 2;
static int countBad = 0;
public static double LengthLine(double x1, double y1, double x2, double y2) {
return Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2));
}
public String mathResult() {
double[][] coord = {
{4.2, 4.6},
{4, 5},
{5.1, 7.4},
{2.1, 4},
{4.7, 4.4},
{4.8, 4.8},
{4.3, 5.3},
{5, 5.4},
{6.5, 8}
};
int count = coord.length;
//poisk centr tag
double cgX = 0;
double cgY = 0;
for (int i = 0; i < count; i++) {
cgX += coord[i][0];
cgY += coord[i][1];
}
cgX /= count;
cgY /= count;
double length[] = new double[count]; // Инициализация массива
for (int i = 0; i < count; i++) {
length[i] = LengthLine(coord[i][0], coord[i][1], cgX, cgY);
if (length[i] > lengthBad) {
countBad += 1;
}
}
double result = ((double) countBad / count) * 100;
String cords = "";
String len = "";
for (int zxc = 0; zxc < count; zxc++) {
for (int n = 0; n < 2; n++) {
cords += coord[zxc][n] + " ";
}
cords += "\n";
len += length[zxc] + "\n";
}
System.out.println(cords);
System.out.println(len);
return cords;
}
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main frame = new Main();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Main() {
setResizable(false);
setAlwaysOnTop(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 500, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("Координаты пробоин");
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel.setBounds(10, 11, 144, 33);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Расстояния");
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_1.setBounds(186, 11, 89, 33);
contentPane.add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("Критерии отбраковки");
lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_2.setBounds(318, 11, 156, 33);
contentPane.add(lblNewLabel_2);
JLabel lblNewLabel_3 = new JLabel("Результат");
lblNewLabel_3.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_3.setBounds(318, 132, 144, 33);
contentPane.add(lblNewLabel_3);
JTextPane labelCord = new JTextPane();
labelCord.setText("");
labelCord.setBackground(new Color(240, 240, 240));
labelCord.setBounds(10, 65, 144, 185);
contentPane.add(labelCord);
JTextPane labelLength = new JTextPane();
labelLength.setBackground(SystemColor.menu);
labelLength.setBounds(164, 65, 144, 185);
contentPane.add(labelLength);
JTextPane labelCriteria = new JTextPane();
labelCriteria.setBackground(SystemColor.menu);
labelCriteria.setBounds(318, 54, 144, 56);
contentPane.add(labelCriteria);
JTextPane labelResult = new JTextPane();
labelResult.setBackground(SystemColor.menu);
labelResult.setBounds(318, 176, 144, 56);
contentPane.add(labelResult);
labelCord.setText(mathResult());
}
} |
|
|
Скорее опыта мало,что бы вас понять.
Добавлено через 24 секунды

Сообщение от Coffeini
NeLonS, русский не разумеете?
Ну вот оба описанных способа:
1
| Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
| import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextPane;
import java.awt.Color;
import java.awt.SystemColor;
import javax.swing.JTextField;
public class Main extends JFrame {
static int lengthBad = 2;
static int countBad = 0;
private final JTextPane labelCord;
public static double LengthLine(double x1, double y1, double x2, double y2) {
return Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2));
}
public void mathResult() {
double[][] coord = {
{4.2, 4.6},
{4, 5},
{5.1, 7.4},
{2.1, 4},
{4.7, 4.4},
{4.8, 4.8},
{4.3, 5.3},
{5, 5.4},
{6.5, 8}
};
int count = coord.length;
//poisk centr tag
double cgX = 0;
double cgY = 0;
for (int i = 0; i < count; i++) {
cgX += coord[i][0];
cgY += coord[i][1];
}
cgX /= count;
cgY /= count;
double length[] = new double[count]; // Инициализация массива
for (int i = 0; i < count; i++) {
length[i] = LengthLine(coord[i][0], coord[i][1], cgX, cgY);
if (length[i] > lengthBad) {
countBad += 1;
}
}
double result = ((double) countBad / count) * 100;
String cords = "";
String len = "";
for (int zxc = 0; zxc < count; zxc++) {
for (int n = 0; n < 2; n++) {
cords += coord[zxc][n] + " ";
}
cords += "\n";
len += length[zxc] + "\n";
}
System.out.println(cords);
System.out.println(len);
labelCord.setText(cords);
}
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main frame = new Main();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Main() {
setResizable(false);
setAlwaysOnTop(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 500, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("Координаты пробоин");
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel.setBounds(10, 11, 144, 33);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Расстояния");
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_1.setBounds(186, 11, 89, 33);
contentPane.add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("Критерии отбраковки");
lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_2.setBounds(318, 11, 156, 33);
contentPane.add(lblNewLabel_2);
JLabel lblNewLabel_3 = new JLabel("Результат");
lblNewLabel_3.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_3.setBounds(318, 132, 144, 33);
contentPane.add(lblNewLabel_3);
JTextPane labelCord = new JTextPane();
labelCord.setText("");
labelCord.setBackground(new Color(240, 240, 240));
labelCord.setBounds(10, 65, 144, 185);
contentPane.add(labelCord);
this.labelCord = labelCord;
JTextPane labelLength = new JTextPane();
labelLength.setBackground(SystemColor.menu);
labelLength.setBounds(164, 65, 144, 185);
contentPane.add(labelLength);
JTextPane labelCriteria = new JTextPane();
labelCriteria.setBackground(SystemColor.menu);
labelCriteria.setBounds(318, 54, 144, 56);
contentPane.add(labelCriteria);
JTextPane labelResult = new JTextPane();
labelResult.setBackground(SystemColor.menu);
labelResult.setBounds(318, 176, 144, 56);
contentPane.add(labelResult);
mathResult();
}
} |
|
2
| Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
| import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextPane;
import java.awt.Color;
import java.awt.SystemColor;
import javax.swing.JTextField;
public class Main extends JFrame {
static int lengthBad = 2;
static int countBad = 0;
public static double LengthLine(double x1, double y1, double x2, double y2) {
return Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2));
}
public String mathResult() {
double[][] coord = {
{4.2, 4.6},
{4, 5},
{5.1, 7.4},
{2.1, 4},
{4.7, 4.4},
{4.8, 4.8},
{4.3, 5.3},
{5, 5.4},
{6.5, 8}
};
int count = coord.length;
//poisk centr tag
double cgX = 0;
double cgY = 0;
for (int i = 0; i < count; i++) {
cgX += coord[i][0];
cgY += coord[i][1];
}
cgX /= count;
cgY /= count;
double length[] = new double[count]; // Инициализация массива
for (int i = 0; i < count; i++) {
length[i] = LengthLine(coord[i][0], coord[i][1], cgX, cgY);
if (length[i] > lengthBad) {
countBad += 1;
}
}
double result = ((double) countBad / count) * 100;
String cords = "";
String len = "";
for (int zxc = 0; zxc < count; zxc++) {
for (int n = 0; n < 2; n++) {
cords += coord[zxc][n] + " ";
}
cords += "\n";
len += length[zxc] + "\n";
}
System.out.println(cords);
System.out.println(len);
return cords;
}
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main frame = new Main();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Main() {
setResizable(false);
setAlwaysOnTop(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 500, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("Координаты пробоин");
lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel.setBounds(10, 11, 144, 33);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Расстояния");
lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_1.setBounds(186, 11, 89, 33);
contentPane.add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("Критерии отбраковки");
lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_2.setBounds(318, 11, 156, 33);
contentPane.add(lblNewLabel_2);
JLabel lblNewLabel_3 = new JLabel("Результат");
lblNewLabel_3.setFont(new Font("Tahoma", Font.PLAIN, 14));
lblNewLabel_3.setBounds(318, 132, 144, 33);
contentPane.add(lblNewLabel_3);
JTextPane labelCord = new JTextPane();
labelCord.setText("");
labelCord.setBackground(new Color(240, 240, 240));
labelCord.setBounds(10, 65, 144, 185);
contentPane.add(labelCord);
JTextPane labelLength = new JTextPane();
labelLength.setBackground(SystemColor.menu);
labelLength.setBounds(164, 65, 144, 185);
contentPane.add(labelLength);
JTextPane labelCriteria = new JTextPane();
labelCriteria.setBackground(SystemColor.menu);
labelCriteria.setBounds(318, 54, 144, 56);
contentPane.add(labelCriteria);
JTextPane labelResult = new JTextPane();
labelResult.setBackground(SystemColor.menu);
labelResult.setBounds(318, 176, 144, 56);
contentPane.add(labelResult);
labelCord.setText(mathResult());
}
} |
|
|
Но всё же спасибо большое!
0
|