package day1;
import java.io.*;
public class Test1 {
public static void main(String[] args) {
System.out.println("Programming in Java is fun!");
}
}
package day1;
import java.io.*;
public class Test2 {
public static void main(String args[]) {
System.out.println("Hello word!");
}
}
package day1;
import java.util.Scanner;
/*
“输入n表示做n次下面的操作:
输入两个正整数,输出它们的和。
例:
输入:
2 //表示n=2,做两次操作
10 11
20 30
输出:
sum=21
sum=50
*/
public class Test3 {
public static void main(String[] args) {
int n, a, b, i, sum;
Scanner sc = new Scanner(System.in);
System.out.println("请输入求和的次数:");
n = sc.nextInt();
for (i = 1; i <= n; i++) {
System.out.println("请输入第一个数:");
a = sc.nextInt();
System.out.println("请输入第二个数:");
b = sc.nextInt();
sum = a + b;
System.out.println("两个数的和为:" + sum);
}
}
}
package day1;
import java.io.*;
import java.util.Scanner;
/*
输入整数a和b,计算并输出a、b的和与差。
例:
输入:
2-8
输出:
The sum is -6
The difference is 10
*/
public class Test4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个整数:");
int a = sc.nextInt();
System.out.println("请输入第二个整数:");
int b = sc.nextInt();
int sum = a + b;
int diff = a - b;
System.out.println("The sum is " + sum);
System.out.println("The difference is " + diff);
}
}
package day1;
import java.io.*;
import java.util.Scanner;
/*
输入1个实数x,计算并输出其平方根。
例:
输入:
1.21
输出:
The square root of 1.21 is 1.1
*/
public class Test5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个实数:");
double x = sc.nextDouble();
double root = Math.sqrt(x);
System.out.println("The square root of " + x + " is " + root);
}
}