Question:
java programming-question?
Ben S
2008-10-27 12:01:18 UTC
I am attempting to work out the following question: Write a program that will ask for three integers to be entered. It should display the following messages:

The largest number entered was: XX
The smallest number entered was: YY

(with the relevant numbers substituted in for XX and YY)

I can really see where to go from, so far I have:

import java.util.Scanner;
}
public static void main(String[]args)
Scanner input=new Scanner(System.in);
{
//variables declared

double integer1,integer2,integer3, highest integer, lowest integer
string XX, YY

System.out.print("What is your first integer value?");
integer1=(input.next.Double();

System.out.print("what is your second integer value?");
integer2=(input.nextDouble();

System.out.print("What is your third integer value?");
integer3=input.nextDouble();




}
}

Cn anybody give me any advice or hints to go by?
Four answers:
Plain Vanilla
2008-10-27 12:24:08 UTC
Once you get the first 2 integers you should set the values for the highest and lowest integers. Then get the third integer and compare the highest and lowest values recorded to the third integer.



System.out.print("What is your first integer value?");

integer1=(input.next.Double();



System.out.print("what is your second integer value?");

integer2=(input.nextDouble();



if (integer1
lowest_integer=integer1;

highest_integer=integer2;

} else{

lowest_integer=integer2;

highest_integer=integer1;

}

//get the 3rd integer

System.out.print("What is your third integer value?");

integer3=input.nextDouble();



if(integer3
lowest_integer=integer3;

}



if(integer3>highest_integer){

highest_integer=integer3;

}



System.out.println("lowest " + lowest_integer);

System.out.println("highest " + highest_integer);
2008-10-27 19:12:01 UTC
well, one of your brackets is in the wrong place (there should be one immediately after the main method and not after the scanner declaration).



You're also naming your variables with spaces, which is not something you can do in Java. Also, you're calling your double variables "integer" when they aren't integers. Use "int" for integers, not doubles. When you actually grab the data, you don't need the "(" after the "=".



Finally, you need to compare all 3 values together and determine which is the max and which is the min and output them accordingly. Use if statements.
citricfuntoosh
2008-10-27 19:07:42 UTC
Well there is a forum on java run by kathy seira. its known as



www.javaranch.com logon on to it. this will definitely help u out.



some other forums regarding java are:

www.serverside.com



By the way where is ur class. u have a method. import statement should be the first statement in a java program followed by class, assignments and then methods. how come u closed import statement.

import java.util.Scanner;

}
2008-10-27 19:20:38 UTC
w8!:D

can someone plz help me with this:

http://ca.answers.yahoo.com/question/?qid=20081022110539AAc4TU7

tanx :D!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...