Write a java program that will sort three integers. The integers are entered from the key board and sorted in variables m1, m2, and m3 respectively. The programs sorts the numbers so that
M1≤ M2≥ M3
M1≤ M2≥ M3
Solution:
import javax.swing.JOptionPane;
/** * * @author Administrator */
public class Main {
public Main() {
public Main() {
}
public static void main(String[] args) {
public static void main(String[] args) {
//Get Three inputs from users, and convert them to integers
int m1=Integer.parseInt(JOptionPane.showInputDialog("please enter first number"));
int m2=Integer.parseInt(JOptionPane.showInputDialog("please enter second number"));
int m3=Integer.parseInt(JOptionPane.showInputDialog("please enter third number"));
//if m1 greater than m2 and m3, then m1 is the greatest
if(m1>=m2&&m1>=m3)
JOptionPane.showMessageDialog(null,""+m2+m1+m3);
else if(m2>=m3)//Else if m2 greater than m3, then m2 is the greatest
JOptionPane.showMessageDialog(null,""+m1+m2+m3);
else//Else m3 will be the greatest
JOptionPane.showMessageDialog(null,""+m1+m3+m2);
}
}
}




0 comments:
إرسال تعليق