import java.util.Scanner; public class Test1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter three numbers: "); float number1 = input.nextInt(); float number2 = input.nextInt(); float number3 = input.nextInt(); float number4 = input.nextInt(); // Compute average double average = (number1 + number2 + number3 + number4) / 4; // Display result System.out.println(average); } } When a user enters 1 2 3 4 during the program execution what will be the exact output? Group of answer choices2.02.53.0The program gives an error.
Question
import java.util.Scanner; public class Test1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter three numbers: "); float number1 = input.nextInt(); float number2 = input.nextInt(); float number3 = input.nextInt(); float number4 = input.nextInt(); // Compute average double average = (number1 + number2 + number3 + number4) / 4; // Display result System.out.println(average); } } When a user enters 1 2 3 4 during the program execution what will be the exact output? Group of answer choices2.02.53.0The program gives an error.
Solution
The exact output will be 2.5. This is because the program is asking for four numbers, and then it calculates the average of these numbers. In this case, the numbers are 1, 2, 3, and 4. The sum of these numbers is 10, and when you divide by 4 (the total number of inputs), the result is 2.5.
Similar Questions
Select the correct answerWhat will be the output of the following Java code?class average { public static void main(String args[]) { double num[] = { 1.9 , 5.4 , 9.5 , 1.2, 5.2 ,0.5}; double result; result = 0; for (int i = 0; i < 6; ++i) result = result + num[i]; System.out.print(result/6); } }Options3.94999999999999973.9999999443.3943.4999999999
import java.util.Scanner;public class Question64{ public static void main(String[] args) { double sum = 0.0; double standardDeviation = 0.0; double mean = 0.0; double res = 0.0; double sq = 0.0; Scanner sc = new Scanner(System.in); int num = sc.nextInt(); double arr[] = new double[num]; for (int i = 0; i < num; i++) { arr[i] = sc.nextDouble(); }
Test time left: 19:22Select the correct answerWhat will be the output of the following Java code?class average { public static void main(String args[]) { double num[] = { 1.9 , 5.4 , 9.5 , 1.2, 5.2 ,0.5}; double result; result = 0; for (int i = 0; i < 6; ++i) result = result + num[i]; System.out.print(result/6); } }Options3.9999999443.3943.94999999999999973.4999999999
Problem StatementWrite a program to find the average of N numbers. Print the average in 2 digit precision DO NOT USE ARRAYInput FormatFirst line consist of a single integer - 'N'Second line consist of N space separated integersOutput FormatDisplay the average of N numbersSample Input51 2 3 4 5Sample Output3.00
code this in java using patterns: Specification: Read in integers until the user enters -1. If there was at least one integer, show the average value.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.