arrangevalue.txt

来自「java的一经典教程」· 文本 代码 · 共 46 行

TXT
46
字号
// Program to read in values for two variables and store the
// larger value in largerValue and the smaller in smallerValue

import javax.swing.JOptionPane;

public class ArrangeValues
{

   public static void largeSmall()
   {
	   int largerValue, smallerValue;
	   String numStr;

	   // Get the numbers

	   numStr = JOptionPane.showInputDialog(
	      "First Integer?: ");
	   largerValue = Integer.parseInt(numStr);

	   numStr = JOptionPane.showInputDialog(
	      "Second Integer?: ");
	   smallerValue = Integer.parseInt(numStr);

	   if (largerValue > smallerValue)
		   JOptionPane.showMessageDialog(null,
		      "Values were already in correct variables");
	   else  //swap them round
	   {
		   int temp;
		   temp = largerValue;
		   largerValue = smallerValue;
		   smallerValue = temp;
		   JOptionPane.showMessageDialog(null,
		      "Values have been moved into correct variables");
	   }
   }


   public static void main(String[] args)
   {
	   largeSmall();

	   System.exit(0);
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?