Created
December 13, 2016 09:14
-
-
Save i0nyx/cb25f32396cef0212d4022f839bfde85 to your computer and use it in GitHub Desktop.
Glava 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Составить программу, которая запрашивает пароль (например, | |
четырехзначное число) до тех пор, пока он не будет правильно введен. | |
*/ | |
package gl_1.zadanie_gl_1; | |
import java.util.Scanner; | |
public class N_4 { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Введите паль из 4 цифр:"); | |
int pas = 0; | |
while(sc.hasNextInt()){ | |
pas = sc.nextInt(); | |
String s = Integer.toString(pas); | |
if(s.length() == 4){ | |
pas = Integer.valueOf(s); | |
System.out.println("Ваш пароль: " + pas); | |
break; | |
}else{ | |
System.out.println("Пароль должнет состоять из 4 цифр!\nПопробуйте снова:"); | |
continue; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment