Computer Science, asked by tristysapack, 6 months ago

Input four numbers and find the average. Make sure the answer includes a decimal portion

Answers

Answered by manojmanu03032003
0

Answer:

Java exercises and solution: Write a program in Java to read 5 numbers from keyboard and find their sum and average.

Explanation:

plz mark as brainlist answer

Answered by shaima961
3

Explanation:

I have a problem in showing the decimals on the average. It keeps showing .00 or .1. I tried to put it in double, but I still get the same results.Also, I want to include the first integer that I input to the sum, but I have no idea how.Please help:

import java.io.*;

import java.util.*;

public class WhileSentinelSum

{

static final int SENTINEL= -999;

public static void main(String[] args)

{

// Keyboard Initialization

Scanner kbin = new Scanner(System.in);

//Variable Initialization and Declaration

int number, counter;

int sum =0;

int average;

//Input

System.out.print("Enter an integer number: " );

number = kbin.nextInt();

counter=0;

//Processing

//Output

while(number != SENTINEL)

{

counter++;

System.out.print("Enter an integer number: ");

number = kbin.nextInt();

sum += number;

}

if (counter !=0)

System.out.println("\nCounter is: " + counter);

else

System.out.println("no input");

average= sum/counter;

System.out.println("The sum is " + sum);

System.out.println("The average is " + average);

System.out.println();

}//end main

}//end class

Similar questions