Advertisement
dxvmxnd

Untitled

Sep 16th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main{
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. int sum;
  8. int num1, num2;
  9. boolean isNotCorrect;
  10.  
  11.  
  12. System.out.println("Снова сумма, гойда");
  13.  
  14. num1 = 0;
  15. do {
  16. isNotCorrect = false;
  17. System.out.println("Введи число 1");
  18. try{
  19. num1 = Integer.parseInt(scan.nextLine());
  20. } catch(NumberFormatException exception) {
  21. isNotCorrect = true;
  22. }
  23. if ((isNotCorrect) || (num1 < 1)) {
  24. isNotCorrect = true;
  25. System.err.println("Гойда, ошибка");
  26. }
  27. } while (isNotCorrect);
  28.  
  29. num2 = 0;
  30. do {
  31. isNotCorrect = false;
  32. System.out.println("Введи число 2");
  33. try{
  34. num2 = Integer.parseInt(scan.nextLine());
  35. } catch(NumberFormatException exception) {
  36. isNotCorrect = true;
  37. System.out.println("Гойда, ошибка");
  38. }
  39. } while (isNotCorrect);
  40.  
  41. sum = num1 + num2;
  42.  
  43. System.out.println(sum);
  44.  
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement