Question

In: Computer Science

Write a Java program that prompts a user for 10 integers. When completed it outputs the...

Write a Java program that prompts a user for 10 integers. When completed it outputs the highest

number, the lowest number, the number of odd number, and the average of the numbers

Solutions

Expert Solution

The code is :

import java.io.*;

class Main {

public static void main(String[] args)throws IOException

{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int a[]=new int[10];

int i,j,c=0;

double s=0.0,avg=0.0;

System.out.println("Enter 10 numbers");

for(i=0;i<10;i++)

{

a[i]=Integer.parseInt(br.readLine()); // enter numbers

}

int max=a[0],min=a[0];

for(i=0;i<10;i++)

{

if(a[i]>max) // max check

{

max=a[i];

}

if(a[i]<min) //min check

{

min=a[i];

}

s=s+a[i];

avg=s/10; // average computation

if(a[i]%2!=0) // odd number checking

{

c++;

}

}

System.out.println("Highest number is "+max);

System.out.println("Lowest number is "+min);

System.out.println("Number of odd numbers are "+c);

System.out.println("Average is "+avg);

}

}

The screenshot of the code is :

The screenshot of the output is :


Related Solutions

Write a program that prompts user to enter integers one at a time and then calculates...
Write a program that prompts user to enter integers one at a time and then calculates and displays the average of numbers entered. Use a while loop and tell user that they can enter a non-zero number to continue or zero to terminate the loop. (Switch statement) Write a program that prompts user to enter two numbers x and y, and then prompts a short menu with following 4 arithmetic operations: Chose 1 for addition Chose 2 for subtraction Chose...
Write a program in JAVA that prompts the user for a lower bound and an upper...
Write a program in JAVA that prompts the user for a lower bound and an upper bound. Use a loop to output all of the even integers within the range inputted by the user on a single line.
You are required to write an interactive program that prompts the user for two integers X...
You are required to write an interactive program that prompts the user for two integers X and Y and performs the following tasks: Adds two numbers Subtracts Y from X Multiplies X and Y Divides X by Y Finds which numbers is larger X oy Y) Prints all the results (a , b, c, d, and e) Program requirements: -     The program should run as many times as the users wish -     The program should be fully documented. -   ...
C++ Write a program that prompts the user to enter 50 integers and stores them in...
C++ Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs separated by a ';'. An example of the program is shown below: list[0] = 15 is the sum of: ----------------------...
Write a JAVA program that prompts the user for the number of names they’d like to...
Write a JAVA program that prompts the user for the number of names they’d like to enter. Create a new array of the size chosen by the user and prompt the user for each of the names. Output the list of names in reverse order.
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
Write a JAVA program that prompts the user to enter a single name. Use a for...
Write a JAVA program that prompts the user to enter a single name. Use a for loop to determine if the name entered by the user contains at least 1 uppercase and 3 lowercase letters. If the name meets this policy, output that the name has been accepted. Otherwise, output that the name is invalid.
Write a Java program that prompts the user to enter a list of integer values and...
Write a Java program that prompts the user to enter a list of integer values and displays whether the list is sorted in increasing order or not. Here is a sample run. Note that the first number in the input indicates the number of the elements in the list. <Output> Enter list: 8 101516619111 The list is not sorted <End Output <Output> Enter list: 10 11344579 11 21 The list is already sorted <End Output Create a complete class for...
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
In Java: Write a program that prompts the user to enter a positive number until the...
In Java: Write a program that prompts the user to enter a positive number until the user input a negative number. In the end, the program outputs the sum of all the positive numbers. You should use do-while loop (not while, not for). You cannot use break or if statement in the lab. Hint: if the program adds the last negative number to your sum, you can subtract the last number from the sum after the loop.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT