Answer to Question #276680 in Java | JSP | JSF for Bella Wang

Question #276680

Write a program using one-dimensional array that determines the highest value among the five input values from the keyboard and prints the difference of each value from the highest.


enter five numbers: 10 20 15 7 8

the highest is: 20

the difference from the highest are:

20 – 10 = 10

20 – 20 = 0

20 – 15 = 5

20 – 7 = 13

20 – 8 = 12

1
Expert's answer
2021-12-07T09:21:32-0500
import java.util.Scanner;


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		int numbers[] = new int[5];


		System.out.print("enter five numbers: ");
		for (int i = 0; i < numbers.length; i++) {
			numbers[i] = keyBoard.nextInt();
		}
		int highest = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			if (highest < numbers[i]) {
				highest = numbers[i];
			}
		}
		System.out.println("the highest is: " + highest);
		System.out.println("the difference from the highest are:");
		for (int i = 0; i < numbers.length; i++) {
			System.out.printf("%d – %d = %d\n", highest, numbers[i], (highest - numbers[i]));
		}
		keyBoard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS