質問編集履歴
3
質問内容の変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
三角形の辺の値を3つ入力し、三角形が成立するかしないかを確認できるようにしたい
|
test
CHANGED
@@ -1,11 +1,105 @@
|
|
1
|
-
|
1
|
+
以下のプログラムでユーザーが0または負の数を入力した場合に"Error:入力する数値xは1≦xでなければならない"と表示されるようにし、その辺の値を再入力するようにしたいのですがどこにそのプログラムを入れれば良いでしょうか?
|
2
2
|
|
3
|
+
```Java
|
3
4
|
|
5
|
+
import java.util.Scanner;
|
4
6
|
|
5
|
-
|
7
|
+
public class Assignment
|
6
8
|
|
9
|
+
{
|
7
10
|
|
11
|
+
public static void main(String[] args)
|
12
|
+
|
13
|
+
{
|
14
|
+
|
15
|
+
System.out.println("Welcome to my first assignment!");
|
16
|
+
|
17
|
+
Scanner input = new Scanner (System.in);
|
18
|
+
|
19
|
+
int SideA;
|
20
|
+
|
21
|
+
int SideB;
|
22
|
+
|
23
|
+
int SideC;
|
24
|
+
|
25
|
+
int result = 1;
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
while (result == 1)
|
30
|
+
|
31
|
+
{
|
32
|
+
|
33
|
+
do
|
34
|
+
|
35
|
+
{
|
36
|
+
|
37
|
+
System.out.println("Enter side A");
|
38
|
+
|
39
|
+
SideA = input.nextInt();
|
40
|
+
|
41
|
+
System.out.println("Enter side B");
|
42
|
+
|
43
|
+
SideB = input.nextInt();
|
44
|
+
|
45
|
+
System.out.println("Enter side C");
|
46
|
+
|
47
|
+
SideC = input.nextInt();
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
if (SideA <1 || SideB <1 || SideC <1)
|
52
|
+
|
53
|
+
{
|
54
|
+
|
55
|
+
System.out.println("Error: numbers must be greater than or equal to 1");
|
56
|
+
|
57
|
+
System.out.println("Enter 1 to continue, or 0 to exit!");
|
58
|
+
|
59
|
+
result = input.nextInt();
|
60
|
+
|
61
|
+
break;
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
else if (SideA+SideB < SideC || SideA+SideC < SideB || SideB+SideC < SideA)
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
System.out.println("These numbers do not make a triangle");
|
70
|
+
|
71
|
+
System.out.println("Enter 1 to continue, or 0 to exit!");
|
72
|
+
|
73
|
+
result = input.nextInt();
|
74
|
+
|
75
|
+
break;
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
else
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
System.out.println("These numbers make a triangle");
|
84
|
+
|
85
|
+
System.out.println("Enter 1 to continue, or 0 to exit!");
|
86
|
+
|
87
|
+
result = input.nextInt();
|
88
|
+
|
89
|
+
break;
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
}while (SideA <1 || SideB <1 || SideC <1 || SideA+SideB < SideC || SideA+SideC < SideB || SideB+SideC < SideA);
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
```
|
8
104
|
|
9
105
|
1. When the user enters a number for the side of a triangle, if the number is less than 1, the program must say "Error: numbers must be greater than or equal to 1" and then the program asks the user to enter the number for that side again
|
10
|
-
|
11
|
-
2. After the program receives 3 positive numbers and determines if it is a triangle or not, the program then asks "Enter 0 to end or 1 to repeat". If the user enters 0, the program ends. If the user enters 1, the program repeats and asks the user for 3 new sides of a potential triangle. You do not have to check if the user enters anything other than 0 or 1
|
2
指摘を受けましたが授業中のため課題の内容を添付させていただきました。和訳は後程追記させていただきます。ご了承ください。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
|
1
|
+
Write a Java program that asks the user for 3 non negative integers that represent the lengths 3 sides of a triangle. After the user enters the numbers, the program determines if the 3 numbers make a valid triangle. If the 3 sides can make a triangle, the program prints "These numbers make a triangle". Otherwise, it prints "These numbers do not make a triangle"
|
2
2
|
|
3
|
-
一旦自分でやってみます
|
4
3
|
|
5
|
-
|
4
|
+
|
5
|
+
Additional requirements:
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
1. When the user enters a number for the side of a triangle, if the number is less than 1, the program must say "Error: numbers must be greater than or equal to 1" and then the program asks the user to enter the number for that side again
|
10
|
+
|
11
|
+
2. After the program receives 3 positive numbers and determines if it is a triangle or not, the program then asks "Enter 0 to end or 1 to repeat". If the user enters 0, the program ends. If the user enters 1, the program repeats and asks the user for 3 new sides of a potential triangle. You do not have to check if the user enters anything other than 0 or 1
|
1
ご迷惑をお掛けし申し訳ございませんでした。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,25 +1,5 @@
|
|
1
1
|
###前提・実現したいこと
|
2
2
|
|
3
|
-
|
3
|
+
一旦自分でやってみます
|
4
4
|
|
5
|
-
Javaでユーザーが三角形の3辺の値を入力して三角形になるか否か(Error)を表示させるプログラムの課題が出されました。正直書き始めのところ以外全くわかりません。
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
import java.util.Scanner;
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
public class Assignment
|
14
|
-
|
15
|
-
{
|
16
|
-
|
17
|
-
public static void main(String[] args)
|
18
|
-
|
19
|
-
{
|
20
|
-
|
21
|
-
|
5
|
+
ご指摘いただきありがとうございます。
|
22
|
-
|
23
|
-
}
|
24
|
-
|
25
|
-
}
|