Arg... Guys can you correct my code?
'coz it gives me a wrong output if i input "3 , 1, 2 or 1, 3, 2 or 3, 2 ,1"

import javax.swing.*;

public class OutputGreatest
{
	public static void main(String[] args)
	{
		
		
		int uInput1,uInput2,uInput3;
		int maxValue;
		
		uInput1	= Integer.parseInt(JOptionPane.showInputDialog(null,"<1>Input a number : "));
		uInput2	= Integer.parseInt(JOptionPane.showInputDialog(null,"<2>Input a number : "));
		uInput3	= Integer.parseInt(JOptionPane.showInputDialog(null,"<3>Input a number : "));
		

				
		maxValue = (uInput1 > uInput2 || uInput1 > uInput3)? +uInput1: +uInput2;
	
		maxValue = (uInput2 > uInput1 || uInput2 > uInput3)? +uInput2: +uInput1;
		
		maxValue = (uInput3 > uInput1 || uInput3 > uInput2)? +uInput3: +uInput2;
		
		
		JOptionPane.showMessageDialog(null,"Greatest value is: "+maxValue );
		System.exit(0);
	}
	
}

Recommended Answers

All 2 Replies

It should be && instead of ||
And why do you use the + It is not necessary.
Also you don't need this:

(uInput1 > uInput2 || uInput1 > uInput3)? +uInput1: +uInput2

If the uInput1 is not the max, then why do you assume that the uInput2 is the max?
Use simple if-else if-else statements

Hey!, Thank you for your help.
I solved it in an instant, your so cool.

maxValue=(uInput2>uInput1 && uInput2>uInput3)? uInput2: (uInput3>uInput1 && uInput3>uInput2)? uInput3: uInput1;

-----
Mark as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.