继续利用上节代码,在其下方加入代码:
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());
}
}
- 保存并运行,在console中移动光标到
中文
下方输入任意内容,观察结果。
*+
号可以连接两个字符串,试编写运行下列代码:
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);
}
}
运行并观察结果
网友评论