Ok, I'm VERY new to this whole Java thing - so this is class related. I'd ask my teacher, but my teacher isn't so great at explaining things for some reason. I know this probably simple, but I would appreciate any and all help on this.
Here's a little background info on it:
We're writing a program that prompts the user to enter five decimal numbers. Then, print a message to indicate that the user entered 5 decimal numbers followed by another message that displays all five of the decimal numbers that were entered. We then have to convert each of the five decimal numbers to the nearest integer. After the 5 numbers have been converted, we add the 5 integer numbers together. Then, we have to calculate the average of the 5 integer numbers and finally - print the sum and average.
We have to flush immediately after each statement that accepts the 5 variables. And after that we have to insert individual statements to convert the keyboard input into a decimal number and assign the decimal number to the appropriate decimal variable.
I get it to work for one number, and then I get stuck.
Here's a copy of the code for the one that I get to work:
import java.io.*;
public class Ch2_PrExercise8
{
static BufferedReader keyboard=new
BufferedReader (new InputStreamReader(System.in));
public static void main (String[]args)
throws IOException
{
double number;
System.out.print("Enter a decimal number: ");
System.out.flush();
number=Double.parseDouble(keyboard.readL ine());
System.out.println("The integer nearest to " + number +
"=" + (int) (number + 0.5));
}
My simple logic was telling me to copy that for the rest of them and do the rest from there - but that's not working.
If anyone can help me, I'll kiss the ground they walk on, no joke.
Here's a little background info on it:
We're writing a program that prompts the user to enter five decimal numbers. Then, print a message to indicate that the user entered 5 decimal numbers followed by another message that displays all five of the decimal numbers that were entered. We then have to convert each of the five decimal numbers to the nearest integer. After the 5 numbers have been converted, we add the 5 integer numbers together. Then, we have to calculate the average of the 5 integer numbers and finally - print the sum and average.
We have to flush immediately after each statement that accepts the 5 variables. And after that we have to insert individual statements to convert the keyboard input into a decimal number and assign the decimal number to the appropriate decimal variable.
I get it to work for one number, and then I get stuck.
Here's a copy of the code for the one that I get to work:
import java.io.*;
public class Ch2_PrExercise8
{
static BufferedReader keyboard=new
BufferedReader (new InputStreamReader(System.in));
public static void main (String[]args)
throws IOException
{
double number;
System.out.print("Enter a decimal number: ");
System.out.flush();
number=Double.parseDouble(keyboard.readL
System.out.println("The integer nearest to " + number +
"=" + (int) (number + 0.5));
}
My simple logic was telling me to copy that for the rest of them and do the rest from there - but that's not working.
If anyone can help me, I'll kiss the ground they walk on, no joke.
