Advertisement
Shahar_Goldenberg

hw 28.9.2022

Sep 22nd, 2022 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.48 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class HW289{
  4.     public static Scanner reader = new Scanner(System.in);
  5.     public static void main(String[]args){
  6. //Q1
  7.     System.out.println("Enter wins and losess: ");
  8.     int wins = reader.nextInt();
  9.     int losess = reader.nextInt();
  10.     if(wins > 6 && losess < 5) System.out.println("Advanced to the national competition");
  11.     else System.out.println("Didn't advance to the national competition");
  12.  
  13. //Q2
  14.     System.out.println("Enter the number of years of education and matriculation grade: ");
  15.     int years = reader.nextInt();
  16.     int grade = reader.nextInt();
  17.     if ((years > 12 && grade > 90) || years > 15) System.out.println("Pass");
  18.     else System.out.println("Fail");
  19.  
  20. //Q3
  21.     System.out.println("Enter 3 numbers:");
  22.     int num1 = reader.nextInt();
  23.     int num2 = reader.nextInt();
  24.     int num3 = reader.nextInt();
  25.     if ( num1 == num2 && num2 == num3) System.out.println("The numbers are equal");
  26.     else if (num1 == num2 ^ num2 == num3 ^ num3 == num1) System.out.println("2 numbers are equal");
  27.     else System.out.println("The numbers aren't equal");
  28.  
  29. //Q4
  30.     System.out.println("Enter 2 numbers: ");
  31.     int n1 = reader.nextInt();
  32.     int n2 = reader.nextInt();
  33.     int n3 = reader.nextInt();
  34.     if((n1+n2 > n3) && (n2+n3 > n1) && (n3+n1 > n2)){
  35.         if (n1 == n2 && n2 == n3) System.out.println("Equilateral triangle");
  36.         else if(n1 == n2 ^ n2 == n3 ^ n3 == n1) System.out.println("An isosceles triangle");
  37.         else System.out.println("Triangle");
  38.     }
  39.     else System.out.println("Not a triangle");
  40.  
  41. //Q5
  42.     System.out.println("Insert ID card, marital status, room density and age: ");
  43.     int id = reader.nextInt();
  44.     int family = reader.nextInt();
  45.     int ppr = reader.nextInt();//person per room
  46.     int age = reader.nextInt();
  47.     if ((family == 1 && ppr == 0) || (family == 1 && ppr > 3) || (family == 0 && age > 34)) System.out.println("Eentitled to an apartment");
  48.     else System.out.println("Not entitled to an apartment");
  49.  
  50.  
  51.  
  52.  
  53.  
  54. //Q6
  55.     System.out.println("Insert year, month and day: ");
  56.     int year = reader.nextInt();
  57.     int month = reader.nextInt();
  58.     int day = reader.nextInt();
  59.     if(month < 1 || month > 12 || day < 0)// בדיקת תקינות התאריך
  60.         {System.out.println("There is an error in the date you entered");}
  61.  
  62. // סופי חודשים
  63.     else if((month == 1 || month == 4 || month == 6 || month == 9 || month == 11)&&(day == 30) || (month == 3 || month == 5 || month == 7 || month == 8 || month == 10)&&(day == 31)) // סוף כל החודשים לא כולל 2 ו-12
  64.     {month++; day = 1;}
  65.        
  66.     else if(month == 2 && (year % 4 != 0 || (year % 4 == 0 && year % 400 == 0) && day == 28) || (year % 4 == 0 && year % 400 != 0 && day == 29))
  67.         {month++; day = 1;}// סוף חודש פבואר
  68.        
  69.     else if(month == 12 && day == 31) {month = 1; day = 1; year++;}// סוף שנה
  70.        
  71. // בדיקת תקינות התאריך
  72.     else if((month == 1 || month == 4 || month == 6 || month == 9 || month == 11)&&(day > 31) || (month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)&&(day > 30))
  73.         {System.out.println("There is an error in the date you entered");}
  74.    
  75.     else if(month == 2 && (year % 4 != 0 || (year % 4 == 0 && year % 400 == 0) && day > 28) || (year % 4 == 0 && year % 400 != 0 && day > 29))
  76.         {System.out.println("There is an error in the date you entered");}
  77.  
  78.     else if(month == 12 && day == 31)
  79.         {System.out.println("There is an error in the date you entered");}
  80.  
  81. //אמצע חודש
  82.     else {day++;}
  83.     System.out.println(year+"/"+month+"/"+day);
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement