פתרון המבחן

פתרון שאלה 1

 

 

 

 

א.      הלולאה תתבצע 30000 פעמים

ב.      להדפיס את כל הכפולות של 500 מ – 1 עד 30000 כולל

ג.        

for (int i=500; i<=30000;i=i+500){

       System.out.println(i);

}

 

 

 

פתרון שאלה 3

int num,place,digit,divider,left,right;

System.out.println("please insert num,place,digit");

num = reader.nextInt();

place = reader.nextInt();

digit = reader.nextInt();

divider = (int)Math.pow(10, place-1);

left = num / divider;

right = num % divider;

left = left – (left%10) + digit;

num = left*divider + right;

System.out.println(num);

פתרון שאלה 4

 

int x,y,z;

System.out.println("please insert x,y,z");

x = reader.nextInt();

y = reader.nextInt();

z = reader.nextInt();

if (Math.abs(yz)<x){

      System.out.println("true");

}

else{

      System.out.println("false");

}

פתרון שאלה 5

 

int h1,m1,h2,m2,h3,m3,total;

System.out.println("please insert start time");

h1 = reader.nextInt();

m1 = reader.nextInt();

System.out.println("please insert end time");

h2 = reader.nextInt();

m2 = reader.nextInt();

          

total = (h2*60 + m2)-(h1*60 + m1);

h3 = total / 60;

m3 = total % 60;

System.out.println("the flight takes+ "+h3+" hours and "+m3+" minutes" );