Advertisement
thotfrnk

number1-1.java

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