Advertisement
Guest User

2 загадки

a guest
Feb 25th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class First {
  4.     String st;
  5.     Scanner sc = new Scanner(System.in);
  6.     int a;
  7.     char ch;
  8.     void intro1() {
  9.         System.out.println("Загадка 1");
  10.         System.out.println();
  11.         System.out.println("Какая нота и продукт называются одинаково?");
  12.         st = sc.nextLine();
  13.         st = st.toLowerCase();
  14.         for (a = 3; a>=0 && !(st.equals("соль")); a--) {
  15.             if (a==1) {
  16.                 ch = 'а';
  17.             } else
  18.                 ch = 'и';
  19.             if (a>0) {
  20.                 System.out.println("Неверно. У вас осталось " + a + " попытк" + ch);
  21.                
  22.             }
  23.             if (a==0) {
  24.                 break;
  25.             }
  26.             st = sc.nextLine();
  27.             st = st.toLowerCase();
  28.         }
  29.         if (a>0) {
  30.             System.out.println("Правильно!");
  31.         } else
  32.             System.out.println("Неверно. Попытки закончились.");
  33.     }
  34.     void intro2() {
  35.         System.out.println("Загадка 2");
  36.         System.out.println();
  37.         System.out.println("Какой человек сможет удержать слона?");
  38.         st = sc.nextLine();
  39.         st = st.toLowerCase();
  40.         for (a = 3; a>=0 && !((st.equals("шахматист") || (st.equals("гроссмейстер")))); a--) {
  41.             if (a==1) {
  42.                 ch = 'а';
  43.             } else
  44.                 ch = 'и';
  45.             if (a>0) {
  46.                 System.out.println("Неверно. У вас осталось " + a + " попытк" + ch);
  47.                
  48.             }
  49.             if (a==0) {
  50.                 break;
  51.             }
  52.             st = sc.nextLine();
  53.             st = st.toLowerCase();
  54.         }
  55.         if (a>0) {
  56.             System.out.println("Правильно!");
  57.         } else
  58.             System.out.println("Неверно. Попытки закончились.");
  59.     }
  60. }
  61.  
  62. public class test {
  63.     public static void main(String[] args) {
  64.         Scanner sc = new Scanner(System.in);
  65.         int i;
  66.         First say = new First();
  67.         do {
  68.             System.out.println("Сейчас доступно 2 загадки. Выберите 1 или 2.");
  69.             i = sc.nextInt();
  70.         } while (!(i == 1 || i == 2));
  71.         switch(i) {
  72.         case 1:
  73.             say.intro1();
  74.             break;
  75.         case 2:
  76.             say.intro2();
  77.             break;
  78.         }
  79.        
  80.         sc.close();
  81.     }
  82.        
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement