以下是最近学习java程序设计总结的部分要点,以后还会不断更新。注意:代码程序都是使用Eclipse实现的。
1.实现输入功能。
第一步:一定要在第一行写入import java.util.Scanner;(注意:这行代码最后是要有英文符的分号的。)
import java.util.Scanner;
第二步:在main代码块中写入Scanner sc=new scanner(System.in);(System.in);(注意大小写)
Scanner sc=new scanner(System.in);
第三步:对变量进行输入,我们分别给int类型变量r和double类型变量i输入值。(注意大小写)
int r=sc.nextInt();
double i=nextDouble();
2.实现输出功能
在main代码块中写入System.out.pintln();即可
System.out.println();
3.将以上代码整合到一起,实现输入r和i的值,并且输出r和i的功能。
import java.util.Scanner;
public class hello
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("请分别输入r和i的数字");
int r=sc.nextInt();
double i=sc.nextDouble();
System.out.println(r);
System.out.println(i);
}
}
代码和运行结果截图如下: