How do i create a program in java that lets the user enter three numbers and outputs the largest of the three numbers entered ?
Printable View
How do i create a program in java that lets the user enter three numbers and outputs the largest of the three numbers entered ?
Maybe take a look at some of these books.
http://av.stanford.edu/books/thinking/
You may want to read some java tutorials too...
http://java.sun.com/docs/books/tutorial/
http://www.google.com/search?hl=en&i...orials&spell=1
BTW: You posted in the wrong forum. This is for original tutorials only...
I haven't tested this but it should be what you want.Code:import java.io.*;
public class WordTest
{
public static void main(String args[]) throws IOException
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter first number: ");
int one = Integer.parseInt(input.readLine());
System.out.print("Enter second number: ");
int two = Integer.parseInt(input.readLine());
System.out.print("Enter third number: ");
int three = Integer.parseInt(input.readLine());
if(one>two && one>three){
System.out.println(one + " is the largest number you input");
}
else if(two>one && two>three){
System.out.println(two + " is the largest number you input");
}
else{
System.out.println(three + " is the largest number you input");
}
}
}
edit
You are right phishphreek80, but I can't resist. It can really help some people to actually see the code of a program though. Plus I think there is a little flaw in my program. Maybe I won't fix it, but I will say what it is. There could be a problem if two of the numbers are the same.
h3r3tic: Its nice that you help him out with this, but they aren't going to learn anything if you do their homework for them...
EDIT:
You're right too, it helps to see the code and examples. Thats why I only posted links to references.
More of a point in the right direction.