Advertisement
mmayoub

for example, counter, sum, percen average

Sep 27th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ForExample {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner in = new Scanner(System.in);
  7.  
  8.         int c = 0;
  9.         int sum = 0;
  10.         int i;
  11.         for (i = 0; i < 4; i += 1) {
  12.  
  13.             System.out.print("Enter a number: ");
  14.             int x = in.nextInt();
  15.  
  16.             if (x > 7) {
  17.                 c = c + 1;
  18.                 sum = sum + x;
  19.             }
  20.         }
  21.  
  22.         System.out.println("Count = " + c);
  23.         System.out.println("percentage = " + 100.0 * c / i + "%");
  24.  
  25.         System.out.println("\nSum = " + sum);
  26.         double avg = (double) sum / c;
  27.         avg = Math.round(avg); // (int)(avg*10)/10.0;
  28.  
  29.         System.out.println("Average = " + avg);
  30.  
  31.         in.close();
  32.  
  33.     }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement