public class Test1_01 {
public static void main(String[] args) {
System.out.println("Welcome to Java");
System.out.println("Welcome to Computer Science");
System.out.println("Programming is fun");
}
}
public class Test1_02 {
public static void main(String[] args) {
int num = 5;
for(int i = 0; i < num; i++) {
System.out.println("Welcome to Java");
}
}
}
public class Test1_03 {
public static void main(String[] args) {
System.out.println(" J A V V A");
System.out.println(" J A A V V A A");
System.out.println("J J A A V V A A");
System.out.println(" J J A A V A A");
}
}
public class Test1_04 {
public static void main(String[] args) {
System.out.println("a\ta^2\ta^3");
int num = 4;
for(int i = 1; i <= num; i++) {
System.out.println(i + "\t" + (i * i) + "\t" + (i * i * i));
}
}
}
public class Test1_05 {
public static void main(String[] args) {
double num = (8.5 * 4.5 - 2.5 * 3) / (45.5 - 3.5);
System.out.println(num);
}
}
public class Test1_06 {
public static void main(String[] args) {
int num_start = 1;
int num_end = 9;
int sum = 0;
for(int i = num_start; i <= num_end; i++) {
sum += i;
}
System.out.println(sum);
}
}
public class Test1_07 {
public static void main(String[] args) {
int num_end1 = 11;
int num_end2 = 13;
System.out.println(computer(num_end1));
System.out.println(computer(num_end2));
}
public static double computer(int num_end) {
double sum = 0;
for(int i = 1, n = 0; i <= num_end; i += 2, n++) {
sum += 1.0/(i * Math.pow(-1, n));
}
double number = 4 * sum;
return number;
}
}
public class Test1_08 {
private static final double PI = 3.1415926;
public static void main(String[] args) {
double radius = 5.5;
System.out.println("area is " + getArea(radius));
System.out.println("perimeter is " + getPerimeter(radius));
}
public static double getArea(double radius) {
return radius * radius * PI;
}
public static double getPerimeter(double radius) {
return 2 * radius * PI;
}
}
public class Test1_09 {
public static void main(String[] args) {
double height = 7.9;
double width = 4.5;
System.out.println("area is " + getArea(height, width));
System.out.println("perimeter is " + getPerimeter(height, width));
}
public static double getArea(double height, double width) {
return height * width;
}
public static double getPerimeter(double height, double width) {
return 2 * (height + width);
}
}
public class Test1_10 {
public static void main(String[] args) {
double kil = 14;
double mil = 1.6 * kil;
int time = 45 * 60 + 30;
double hour = time / 3600.0;
System.out.println(mil/hour + "英里/小时");
}
}
public class Test1_11 {
public static void main(String[] args) {
int num = 312032486;
for(int i = 1; i <= 5; i++) {
num = fun(i, num);
System.out.println("第" + i + "年的人口数是: " + num);
}
}
public static int fun(int i, int num) {
int time = 3600 * 24 * 365 * i;
double birth = time / 7.0;
double die = time / 13.0;
double in = time / 45.0;
int change = (int) (birth + in - die);
num += change;
return num;
}
}
public class Test1_12 {
public static void main(String[] args) {
double mil = 24;
double kil = mil / 1.6;
int time = 1 * 3600 + 40 * 60 + 35;
double hour = time / 3600.0;
System.out.println(kil/hour + "公里/小时");
}
}
public class Test1_13 {
public static void main(String[] args) {
double a = 3.4, b = 50.2, e = 44.5, c = 2.1, d = 0.55, f = 5.9;
double x = (e * d - b * f) / (a * d - b * c);
double y = (a * f - e * c) / (a * d - b * c);
System.out.println("x = " + x + "\ty=" + y);
}
}
以上代码均为个人编写,不当之处,悉请指正。