- 输入自己的名字,年龄和性别,分别用不同的变量接收,并将输入的信息做输出。
import java.util.Scanner;
public class TestPerson {
public static void main(String[] args) {
System.out.println("Please input your name here:");
Scanner input = new Scanner(System.in);
String Name = (String) input.next();
System.out.println("Please input your age here:");
int age = input.nextInt();
System.out.println("Please input your gender here:");
String gender = input.next();
System.out.println("The computer recorded that :");
System.out.println("Your nanme is:" + Name);
System.out.println("Your age is:" + age);
System.out.println("Your gender is:" + gender);
}
}
- 计算存款10000元,活期1年、活期2年,定期1年,定期2年后的本息合计。
public class TestDeposit {
public static void main(String[] args) {
int money = 10000;
System.out.println("本金:"+money);
double result1 = money*(1+0.35/100);
System.out.println("活期1年本金总计:"+Math.round(result1));
double result2 = money*(1+1.50/100);
System.out.println("定期1年本金总计:"+Math.round(result2));
double result3 = money*(1+0.35/100*2);
System.out.println("活期2年本金总计:"+Math.round(result3));
double result4 = money*(1+2.10/100*2);
System.out.println("定期2年本金总计:"+Math.round(result4));
}
}