teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

5

改正

2017/01/11 18:16

投稿

退会済みユーザー
answer CHANGED
@@ -3,40 +3,41 @@
3
3
  import java.util.*;
4
4
 
5
5
  public class MPO {
6
- public static void main(String[] args) {
6
+ public static void main(String[] args) {
7
7
 
8
- Scanner sc = new Scanner(System.in);
8
+ Scanner sc = new Scanner(System.in);
9
- int a, b;
9
+ int a=0, b=0;
10
- System.out.print("数1:");
10
+
11
- a = sc.nextInt();
12
- while (a >= 10 || a<1) {
11
+ while (a >= 10 || a<1) {
13
- System.out.print("数1[10未満1以上]:");
12
+ System.out.print("数1[10未満1以上]:");
13
+ String a1 = sc.next();
14
+ try{
15
+ a=Integer.parseInt(a1);
16
+ }catch(Exception e){}
17
+ }
14
18
 
19
+ while (b >= 10 || b<1) {
20
+ System.out.print("数2[10未満1以上]:");
15
- a = sc.nextInt();
21
+ String b1 = sc.next();
22
+ try{
23
+ b=Integer.parseInt(b1);
24
+ }catch(Exception e){}
16
- }
25
+ }
17
- System.out.print("数2:");
18
26
 
19
- b = sc.nextInt();
20
- while (b >= 10 || b<1) {
27
+ while (true) {
21
- System.out.print("数2[10未満1以上]:");
28
+ System.out.print("算術演算子:");
22
- b = sc.nextInt();
29
+ String p = sc.next();
23
- }
24
30
 
25
- while (true) {
26
- System.out.print("算術演算子:");
31
+ if (p.equals("+")) {
27
- String p = sc.next();
28
32
 
33
+ System.out.println(a + b);
34
+ break;
29
- if (p.equals("+")) {
35
+ } else if (p.equals("-")) {
36
+ System.out.println(a - b);
37
+ break;
38
+ }
30
39
 
31
- System.out.println(a + b);
32
- break;
33
- } else if (p.equals("-")) {
34
- System.out.println(a - b);
35
- break;
36
- }
40
+ }
37
-
38
- }
41
+ }
39
- }
40
42
  }
41
-
42
43
  ```

4

改正

2017/01/11 18:16

投稿

退会済みユーザー
answer CHANGED
File without changes

3

改正

2017/01/11 18:16

投稿

退会済みユーザー
answer CHANGED
@@ -9,7 +9,7 @@
9
9
  int a, b;
10
10
  System.out.print("数1:");
11
11
  a = sc.nextInt();
12
- while (a >= 10 || a<0) {
12
+ while (a >= 10 || a<1) {
13
13
  System.out.print("数1[10未満1以上]:");
14
14
 
15
15
  a = sc.nextInt();
@@ -17,7 +17,7 @@
17
17
  System.out.print("数2:");
18
18
 
19
19
  b = sc.nextInt();
20
- while (b >= 10 || b<0) {
20
+ while (b >= 10 || b<1) {
21
21
  System.out.print("数2[10未満1以上]:");
22
22
  b = sc.nextInt();
23
23
  }

2

改正

2017/01/11 18:10

投稿

退会済みユーザー
answer CHANGED
@@ -10,7 +10,7 @@
10
10
  System.out.print("数1:");
11
11
  a = sc.nextInt();
12
12
  while (a >= 10 || a<0) {
13
- System.out.print("数1[10以下1以上]:");
13
+ System.out.print("数1[10未満1以上]:");
14
14
 
15
15
  a = sc.nextInt();
16
16
  }
@@ -18,7 +18,7 @@
18
18
 
19
19
  b = sc.nextInt();
20
20
  while (b >= 10 || b<0) {
21
- System.out.print("数2[10以下1以上]:");
21
+ System.out.print("数2[10未満1以上]:");
22
22
  b = sc.nextInt();
23
23
  }
24
24
 

1

改正

2017/01/11 18:05

投稿

退会済みユーザー
answer CHANGED
@@ -9,16 +9,16 @@
9
9
  int a, b;
10
10
  System.out.print("数1:");
11
11
  a = sc.nextInt();
12
- while (a > 10) {
12
+ while (a >= 10 || a<0) {
13
- System.out.print("数1[10以下]:");
13
+ System.out.print("数1[10以下1以上]:");
14
14
 
15
15
  a = sc.nextInt();
16
16
  }
17
17
  System.out.print("数2:");
18
18
 
19
19
  b = sc.nextInt();
20
- while (b > 10) {
20
+ while (b >= 10 || b<0) {
21
- System.out.print("数2[10以下]:");
21
+ System.out.print("数2[10以下1以上]:");
22
22
  b = sc.nextInt();
23
23
  }
24
24