Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pt1
- import java.util.Scanner;
- public class numberThree {
- public static void main(String[] args) {
- //(3) Re-do question 1 c & d using WHILE loops.
- //(a) 1(c) Allow a user to enter 5 numbers and print the lowest value and how many numbers are between 75 and 100.
- Scanner input = new Scanner (System.in);
- int num, num_count = 0, lowest_num = 101;
- System.out.println("Please enter a number: ");
- num = input.nextInt();
- while (num != 0) {
- System.out.println("Please enter a number: ");
- num = input.nextInt();
- if(num < lowest_num) {
- lowest_num = num;
- }
- if(num >= 75 && num <= 100) {
- num_count++;
- }
- }
- System.out.println("Lowest value: " +lowest_num);
- System.out.println("Numbers between 75 and 100: " +num_count);
- }
- }
- pt2
- import java.util.Scanner;
- public class numberThree2 {
- public static void main(String[] args) {
- //(3)(b) Allow a user to enter 10 numbers and print highest number entered and the average of the numbers.
- Scanner input = new Scanner (System.in);
- double num, num_count = 0, sum = 0, ave, highest_num = -1;
- System.out.println("Please enter a number: ");
- num = input.nextDouble();
- while(num != 0) {
- System.out.println("Please enter a number: ");
- num = input.nextDouble();
- num_count++;
- sum += num;
- if(num > highest_num) {
- highest_num = num;
- }
- }
- ave = sum / num_count;
- System.out.println("Average: " +ave);
- System.out.println("Highest value: " +highest_num);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement