In: Computer Science
java program plz number = 308.2 number = 14.9 number = 7.4 number = 2.8 number = 3.9 number = 4.7 number = -15.4 number = 2.8 Sum = 329.3
Raw_code:
// importing Scanner class
import java.util.Scanner;
public class sum{
// main method
public static void main(String[] args){
// creating Scanner object
Scanner input = new Scanner(System.in);
// temporary variables for storing data
double number = -1, sum = 0;
// while loop runs until user enters 0
while(number != 0){
System.out.print("number = ");
// taking input from user and storing in number
number = input.nextDouble();
// incrementing sum by number
sum += number;
}
// printing sum
System.out.printf("\nSum = %1.2f", sum);
}
}
// program runs until user enters 0