Write a java program that assigns 1 2 3 04 and 3333 to the v
Write a java program that assigns 1, 2, –3, 0.4, and 3.333 to the variables a, b, c, d, and e, respectively. Next, compute their sum. Assign the result to a variable named sum. Next, compute the average of the values in these variables. Assign the result to a variable named average. Display the values in sum and average with appropriate labels. Also have the name Hello World the first printed text to the screen
Solution
SumAverage.java
public class SumAverage {
public static void main(String[] args) {
System.out.println(\"Hello World the first printed text to the screen\");
double a = 1;
double b = 2;
double c = -3;
double d = 0.4;
double e = 3.333;
double sum = a+b+c+d+e;
double average = sum/5;
System.out.println(\"Sum is \"+sum);
System.out.println(\"Average is \"+average);
}
}
Output:
Hello World the first printed text to the screen
Sum is 3.733
Average is 0.7466
