highest number
hi!
I'm trying to get this program code to display the highest of the 3 numbers that the user has to enter, but i don't know what's wrong with it. can any1 help?
import java.io.*;
publicclass maxnumber
{
publicstaticvoid main(String [] args)throws IOException
{
int num1, num2, num3, max0;
BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter 3 numbers");
System.out.println("The highest number will be displayed at the end");
System.out.println("First Number: ");
String input = reader.readLine();
num1 = Integer.parseInt(input);
System.out.print("Second Number: ");
input = reader.readLine();
num2 = Integer.parseInt(input);
System.out.print("Third Number: ");
input = reader.readLine();
num3 = Integer.parseInt(input);
num1 = max0;
if (num2 > num1) max0 = num2;
elseif (num3 > num2) max0 = num3;
System.out.println("The maximum number is " +max0);
}
}
javac-d . -g -nowarn maxnumber.java
maxnumber.java:27: variable max0 might not have been initialized
num1 = max0;
^
1 error
[1923 byte] By [
mark_8206a] at [2007-11-26 14:49:43]

ted, my code is now what appears below but i'm still gettin gthe same error message.
import java.io.*;
public class maxnumber
{
public static void main(String [] args) throws IOException
{
int num1, num2, num3, max0;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter 3 numbers");
System.out.println("The highest number will be displayed at the end");
System.out.println("First Number: ");
String input = reader.readLine();
num1 = Integer.parseInt(input);
System.out.print("Second Number: ");
input = reader.readLine();
num2 = Integer.parseInt(input);
System.out.print("Third Number: ");
input = reader.readLine();
num3 = Integer.parseInt(input);
if (num2 > num1) max0 = num2;
if (num3 > num2) max0 = num3;
System.out.println("The maximum number is " +max0);
}
}
Good day friends
you are trying to asssign like this
num1=max0
variable max0 value is not yet assigned
<insert useless advice that probably doesnt make sense or won't work or is just plain wrong>
Listening to me? Well, thats why u got probelm
wth regards
vasu_gb@still.learning.but.trying.to.advise.even.though.dont.know.what.on.about