Skip to content

Instantly share code, notes, and snippets.

@i0nyx
Created December 13, 2016 09:14
Show Gist options
  • Save i0nyx/cb25f32396cef0212d4022f839bfde85 to your computer and use it in GitHub Desktop.
Save i0nyx/cb25f32396cef0212d4022f839bfde85 to your computer and use it in GitHub Desktop.
Glava 1
/*
Составить программу, которая запрашивает пароль (например,
четырехзначное число) до тех пор, пока он не будет правильно введен.
*/
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