質問編集履歴
2
コードの表示変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,72 @@
|
|
1
|
+
```html
|
2
|
+
import java.util.Scanner;
|
3
|
+
public class assignment5final
|
4
|
+
{
|
5
|
+
public static void main(String [] args){
|
6
|
+
Scanner input = new Scanner(System.in);
|
7
|
+
|
8
|
+
String pass = input.nextLine();
|
9
|
+
|
1
|
-
|
10
|
+
System.out.println("password:" + pass);
|
11
|
+
|
12
|
+
while(true){
|
13
|
+
if(pass == "abc"){
|
14
|
+
break;
|
15
|
+
}else{
|
16
|
+
continue;
|
17
|
+
while(true){
|
18
|
+
|
19
|
+
int i;
|
20
|
+
|
21
|
+
if(pass.length() < 8){
|
22
|
+
System.out.println(" Your password must be at least 8 characters.");
|
23
|
+
}
|
24
|
+
|
25
|
+
for(i = 0; i < pass.length(); i++){
|
26
|
+
if(Character.isUpperCase(pass.charAt(i))){
|
27
|
+
break;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
if(i == pass.length()){
|
31
|
+
System.out.println(" Your password must contain at least one uppercase letter.");
|
32
|
+
}
|
33
|
+
|
34
|
+
for(i = 0; i < pass.length(); i++){
|
35
|
+
if(Character.isLowerCase(pass.charAt(i))){
|
36
|
+
break;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
if(i == pass.length()){
|
40
|
+
System.out.println(" Your password must contain at least one lowercase letter.");
|
41
|
+
}
|
42
|
+
|
43
|
+
for(i = 0; i < pass.length(); i++){
|
44
|
+
if(Character.isDigit(pass.charAt(i))){
|
45
|
+
break;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
if(i == pass.length()){
|
49
|
+
System.out.println(" Your password must contain a numeber.");
|
50
|
+
}
|
51
|
+
|
52
|
+
if(pass.contains("password")){
|
53
|
+
System.out.println(" Your password cannot contain word 'password.'");
|
54
|
+
}
|
55
|
+
|
56
|
+
if(pass.contains(" ")){
|
57
|
+
System.out.println(" You password can only contain aplha numeric characters.");
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
2
65
|
|
66
|
+
|
67
|
+
|
68
|
+
```
|
69
|
+
|
3
70
|
# ユーザーに繰り返しインプットを要求し、特定の文字(この場合abc)が入力されたら、ループを抜け出し、プログラムを終了させたい。
|
4
71
|
|
5
72
|
|
1
コードの解説を追加した
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,3 +1,8 @@
|
|
1
1
|

|
2
2
|
|
3
|
-
# ユーザーに繰り返しインプットを要求し、特定の文字(この場合abc)が入力されたら、ループを抜け出し、プログラムを終了させたい。
|
3
|
+
# ユーザーに繰り返しインプットを要求し、特定の文字(この場合abc)が入力されたら、ループを抜け出し、プログラムを終了させたい。
|
4
|
+
|
5
|
+
|
6
|
+
最初のif文のcontinueを追加すると、それより下の文に行かなくなってしまします。ifがtrueであれば、抜け出し、ループ、インプット要求を停止させ、falseであれば、続け、それぞれのif文へと続けようと思ったのですが、思うように行きません。
|
7
|
+
|
8
|
+
while(true)を使いユーザーに続けてインプットを要求させようとしてます。
|