int count = 0, maxGrade,minGrade,currGrade,sum = 0;
double avg;
System.out.println("please insert the first grade");
currGrade = reader.nextInt();
minGrade = currGrade;
maxGrade = currGrade;
while (currGrade != -999){
count++;
sum += currGrade;
if (currGrade < minGrade){
minGrade = currGrade;
}
if (currGrade > maxGrade){
maxGrade = currGrade;
}
System.out.println("please insert the next grade");
currGrade = reader.nextInt();
}
System.out.println("count = "+count);
System.out.println("max = "+maxGrade);
System.out.println("min = "+minGrade);
avg = (double)sum / count;
System.out.println("avg = "+avg);
חישוב סכום ספרות במספר
int num,tmp,count = 0,sum = 0;
System.out.println("please insert a number");
num = reader.nextInt();
tmp = num;
while (num > 9){
count++;
sum += num % 10;
num = num / 10;
}
sum += num;
count++;
System.out.println("the number "+tmp+" has "+count+" digits");
System.out.println("sum = "+sum);
שיעורי בית
עמ 180, תרגילים 6 עד 10 כולל
עמ 185, תרגילים 16 – 26 כולל