swap.txt

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

TXT
32
字号
// Swaps the values of two variables
import javax.swing.JOptionPane;

public class Swap
{
	public static void main(String[] args)
	{
		// declare and initialise variables
		int first = 3;
		int second = 4;

      // Write out initial values
		JOptionPane.showMessageDialog(null,
		   "First variable: " + first
		   + "\nsecond variable: " + second);

      // swap values
		int temp;
		// temporary variable to facilitate the swap

		temp = first;
      first = second;
      second = temp;

      // Write out new values
		JOptionPane.showMessageDialog(null,
		   "First variable: " + first
		   + "\nsecond variable: " + second);

      System.exit(0);
	}
}

⌨️ 快捷键说明

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