Advertisement
thotfrnk

forloops2.java

Nov 11th, 2022 (edited)
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class number2 {
  3.     public static void main(String[] args) {
  4.  
  5.         /*
  6.         *Write a program to read in twelve numbers. Find and print the sum of the numbers and count
  7.         * the number of numbers that are smaller than 25
  8.          */
  9.  
  10.         Scanner input = new Scanner (System.in);
  11.  
  12.         int h, num, num_count = 0, sum = 0;
  13.  
  14.         System.out.println("Please enter a number: ");
  15.         //num = input.nextInt();
  16.  
  17.         for(h=1; h<=12; h++) {
  18.             System.out.println("Please enter a number: ");
  19.             num = input.nextInt();
  20.  
  21.             sum += num;
  22.  
  23.             if (num < 25) {
  24.                 num_count++;
  25.             }
  26.         }
  27.         System.out.println("Sum: " +sum);
  28.         System.out.println("Amount of numbers under 25: " +num_count);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement