Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- //(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, lowest_num=100, num_count=0;
- //System.out.println("Please enter a number: ");
- //num = input.nextInt();
- for(int i=1; i<=5; i++) {
- 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("Amount of numbers between 75 to 100: " +num_count);
- }
- }
- pt2
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- //(d) 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 = 0;
- for(double m=1; m<=10; m++) {
- 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