Advertisement
thotfrnk

number3.java

Nov 11th, 2022 (edited)
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. pt1
  2.  
  3. import java.util.Scanner;
  4. public class numberThree {
  5.     public static void main(String[] args) {
  6.  
  7.         //(3) Re-do question 1 c & d using WHILE loops.
  8.         //(a) 1(c) Allow a user to enter 5 numbers and print the lowest value and how many numbers are between 75 and 100.
  9.  
  10.         Scanner input = new Scanner (System.in);
  11.  
  12.         int num, num_count = 0, lowest_num = 101;
  13.  
  14.         System.out.println("Please enter a number: ");
  15.         num = input.nextInt();
  16.  
  17.         while (num != 0) {
  18.             System.out.println("Please enter a number: ");
  19.             num = input.nextInt();
  20.  
  21.             if(num < lowest_num) {
  22.                 lowest_num = num;
  23.             }
  24.  
  25.             if(num >= 75 && num <= 100) {
  26.                 num_count++;
  27.             }
  28.         }
  29.         System.out.println("Lowest value: " +lowest_num);
  30.         System.out.println("Numbers between 75 and 100: " +num_count);
  31.     }
  32. }
  33.  
  34. pt2
  35.  
  36. import java.util.Scanner;
  37. public class numberThree2 {
  38.     public static void main(String[] args) {
  39.  
  40.         //(3)(b) Allow a user to enter 10 numbers and print highest number entered and the average of the numbers.
  41.  
  42.         Scanner input = new Scanner (System.in);
  43.  
  44.         double num, num_count = 0, sum = 0, ave, highest_num = -1;
  45.  
  46.         System.out.println("Please enter a number: ");
  47.         num = input.nextDouble();
  48.  
  49.         while(num != 0) {
  50.             System.out.println("Please enter a number: ");
  51.             num = input.nextDouble();
  52.  
  53.             num_count++;
  54.  
  55.             sum += num;
  56.  
  57.             if(num > highest_num) {
  58.                 highest_num = num;
  59.             }
  60.         }
  61.         ave = sum / num_count;
  62.  
  63.         System.out.println("Average: " +ave);
  64.         System.out.println("Highest value: " +highest_num);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement