1. 程式人生 > >Java學習---比較兩個數大小

Java學習---比較兩個數大小

import javax.swing.JOptionPane;
public class Compare{
		public static void main(String[] args){
				String s1,s2;
				s1=JOptionPane.showInputDialog("Please enter the first number:");
				s2=JOptionPane.showInputDialog("Please enter the second number:");
				
				int firstNumber,secondNumber;
				firstNumber=Integer.parseInt(s1);
				secondNumber=Integer.parseInt(s2);
				
				if(firstNumber>secondNumber){
						JOptionPane.showMessageDialog(null,firstNumber+" larger than "+secondNumber);
					}
				else if(secondNumber>firstNumber){
						JOptionPane.showMessageDialog(null,secondNumber+" larger than "+firstNumber);	
					}
				else{
						JOptionPane.showMessageDialog(null,firstNumber+" equal to "+secondNumber);
					}
			}
	}