public class SumFromOneToTen {
public static void main(String[] args){
int sum = 0;
for (int i = 1; i <= 10; i++){
sum += i;
}
System.out.println("1到10的和是: " + sum);
}
}
public class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public void printPersonInfo() {
System.out.println("姓名: " + name + ",年龄:"+ age);
}
public static void main(String[] args){
Person person = new Person("张三",25);
person.printPersonInfo();
}
}
public class FindMaxAndMin {
public static void main(String args) {
int[] numbers = {1, 5, 3, 9, 7};
int max = numbers;
int min = numbers;
for (int i = 1; i < numbers.length; i++) {
if (numbers[i] > max) {
max = numbers[i];
} else if (numbers[i] < min) {
min = numbers[i];
}
}
System.out.println("最大值: " + max);
System.out.println("最小值: " + min);
}
}