作业1:
源码:
package net.day0623;
public class Text1 {
public static void main(String[] args) {
// 定义变量
String name = "小明";
int age = 25;
int workAge = 3;
int projectCount = 5;
String IT = "JAVA";
String hobby = "篮球";
// 输出信息
System.out.println("这个同学的姓名是:"+name);
System.out.println("年龄是:"+age);
System.out.println("工作了"+workAge+"年了");
System.out.println("做过"+projectCount+"个项目");
System.out.println("技术方向是:"+IT);
System.out.println("兴趣爱好:"+hobby);
}
}
运行结果:
作业2:
源码:
package net.day0623;
import java.util.Scanner;
public class Text2 {
// 定义键盘输入
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
// 提示输入信息并且获取输入信息,输出信息
System.out.println("请输入4位会员卡号:");
int num = input.nextInt();
System.out.println("会员卡号:" + num);
}
}
运行结果:
作业3:
源码:
package dome1;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
System.out.print("请输入四位会员卡号:");
Scanner input = new Scanner(System.in);
int no = input.nextInt();
System.out.println("会员卡号:"+no);
int input1 = no%10;
int input2 = no/10%10;
int input3 = no/100%10;
int input4 = no/1000;
System.out.println("千位数:"+input4+",百位数:"+input3+",百位数:"+input2+",个位数:"+input1);
int num = input1 + input2 + input3 + input4;
System.out.println("会员卡号"+ no +"各位之和:"+ num);
}
}
运行结果:
作业4:
源码:
package dome1;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
System.out.print("请输入四位会员卡号:");
Scanner input = new Scanner(System.in);
int no = input.nextInt();
System.out.println("会员卡号:"+no);
int input1 = no%10;
int input2 = no/10%10;
int input3 = no/100%10;
int input4 = no/1000;
System.out.println("千位数:"+input4+",百位数:"+input3+",百位数:"+input2+",个位数:"+input1);
int num = input1 + input2 + input3 + input4;
System.out.println("会员卡号"+ no +"各位之和:"+ num);
if(num >20) {
System.out.println("会员卡号"+no+"的会员,恭喜您中奖了!奖品是MP3!");
}else {
System.out.println("会员卡号"+no+"的会员,很遗憾您未中奖!");
}
}
}
运行结果: