I am have no idea wat is wrong with my code. The system is supposed to get 3 inputs from users and display a message box to show the number in ascending order. If i were to get input from input box and display it in message box it will work perfectly but when i tried to modify it where the input were taken from scanner and display it in message box. The program just stopped when i entered the 3rd integer. Any1 can give me some idea wat is wrong? Here is my code:

import java.util.Scanner;
import javax.swing.JOptionPane;

class lab3q2
{
	public static void main(String[] args)
	{

		Scanner abc = new Scanner(System.in);

		System.out.print("Enter 3 integers\nfirst integer: ");
		int int1 = abc.nextInt();
		System.out.print("\nSecond integer: ");
		int int2 = abc.nextInt();
		System.out.print("\nThird integer: ");
		int int3 = abc.nextInt();

		int min, med, max;
		
		if(int1 > int2)
		{
			med = int1;
			min = int2;
		}
		else
		{
			med = int2;
			min = int1;
		}

		if(int3 > med)
		{
			max = int3;
		}
		else
		{
			max = med;
			med = int3;
		}
	
		JOptionPane.showMessageDialog(null,"The sorted number are "+min+" "+med+" "+max, "SimpleSortingOutput",JOptionPane.INFORMATION_MESSAGE);

Recommended Answers

All 2 Replies

Try adding a System.out.println(); before the JOptionPane to see where the program stops

sorry, i made a mistake. The command window overlapped the message box. It actually working.

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.