1.2.1 输入

2019-02-02  本文已影响3人  harukou_ou

继续利用上节代码,在其下方加入代码:

package hello;

import java.util.Scanner;

public class Hello {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("中文");
        // Use Scanner to accept input:
        Scanner in = new Scanner(System.in);
        System.out.println(in.nextLine());
    }

}
package hello;

import java.util.Scanner;

public class Hello {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("中文");
        // Use Scanner to accept input:
        Scanner in = new Scanner(System.in);
        System.out.println("echo:"+ in.nextLine());
    }

}

eclipse使用技巧: 选中多行可用shift+方向键,使用ctrl+/注释掉无用代码
显示计算2+3结果的代码:

package hello;

import java.util.Scanner;

public class Hello {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("中文");
        // Use Scanner to accept input:
//      Scanner in = new Scanner(System.in);
//      System.out.println("echo:"+ in.nextLine());
        System.out.println("True:"+"2+3="+(2+3));
        System.out.println("False:"+"2+3="+2+3);
    }

}

运行并观察结果

上一篇下一篇

猜你喜欢

热点阅读