פתרון תרגיל 10 + שיעורי הבית

פתרון תרגיל 10 שעשינו בכיתה

int countY = 0, countN = 0;

char ch;

System.out.println("please insert first vote");

ch = reader.next().charAt(0);

while (ch != 'f'){

      if (ch == 'y'){

            countY++;

      }

      if (ch == 'n'){

            countN++;

      }

      System.out.println("please insert next vote");

      ch = reader.next().charAt(0);

}

double sum = countY + countN;

double p = ((int)((countY / sum)*10000))/100.0 ;

if ((countY / sum)>= 0.6){

      System.out.println("The total survey results are: "+countY+" for the reform "+countN+" reject the reform and the reform will strated soon");

      System.out.println("Precented of the survay "+p+"% for the reform");

}

else{

      System.out.println("The total survey results are: "+countY+" for the reform "+countN+" reject the reform and the reform will canceled");

      System.out.println("Precented of the survay "+p+"% for the reform");

}

       

 

שיעורי בית :

עמ 186 תרגילים 21 עד 26 כולל