变量数据类型-练习1:输出个人简历
使用变量存储数据,实现个人简历信息的输出
private static void homework1() {
String name = "小明";
System.out.println("这位同学的姓名是:" + name);
int age = 25;
System.out.println("年龄是:" + age);
int working_year = 3;
System.out.println("工作" + working_year + "年了");
int num_project = 5;
System.out.println("做过" + num_project + "个项目");
String techology = "Java";
System.out.println("技术方向是:" + techology);
String hobby = "篮球";
System.out.println("兴趣爱好是:" + hobby);
}
变量数据类型-练习2:求四位会员卡号之和
键盘输入四位数字的会员卡号
使用“/”和“%”运算符分解获得会员卡各个位上的数字
将各个位上数字求和
private static void homework2() {
System.out.println("请输入四位数的会员卡号:");
Scanner in = new Scanner(System.in);
int num = in.nextInt();
System.out.println("会员卡号是:" + num);
//千位数字
int first;
//百位数字
int second;
//十位数字
int third;
//个位数字
int fourth;
int temp;
first = num / 1000;
temp = num % 1000;
second = temp / 100;
temp = temp % 100;
third = temp / 10;
fourth = temp % 10;
int sum = first + second + third + fourth;
System.out.println("千位数:" + first + " 百位数:" + second + " 十位数:" + third + " 个位数:" + fourth);
System.out.println("会员卡号" + num + "各位之和是: " + sum);
}
循环-练习1:N的阶乘
通过Scanner 获取一个整数,然后使用while计算这个整数的阶乘
N的阶乘等于 N* (N-1) * (N-2) * … * 1
结果: 6!=65432*1=720
private static void homework3() {
Scanner in = new Scanner(System.in);
System.out.print("请输入一个数字: ");
int num = in.nextInt();
int count = num;
System.out.print("阶乘:" + num + "!=" + num);
for (int i = num - 1; i > 0; i--) {
System.out.print("*" + i);
count *= i;
}
System.out.println("=" + count);
}
循环-练习2:输出星期数
从键盘输入一位整数,当输入17时,输出“星期一”“星期日”
输入其他数字时,提示用户重新输入
private static void homework4() {
Scanner in = new Scan