fruit.java

来自「Java2入门经典第二章源码」· Java 代码 · 共 32 行

JAVA
32
字号
import java.io.IOException;  // For code that delays ending the program

public class Fruit 
{
  public static void main(String[] args) 
  {
    // Declare and initialize three variables
    int numOranges = 5;
    int numApples = 10;
    int numFruit = 0;

    // Increment oranges and calculate the total fruit
    numFruit = ++numOranges + numApples; 

    System.out.println("A totally fruity program");
    // Display the result
    System.out.println("Value of oranges is " + numOranges);
    System.out.println("Total fruit is " + numFruit);

    // Code to delay ending the program
    System.out.println("(press Enter to exit)");
    try 
    {
      System.in.read();               // Read some input from the keyboard
    }
    catch (IOException e)             // Catch the input exception
    {
      return;                         // and just return
    }
  }
}

⌨️ 快捷键说明

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