作业1:用户输入两个数a、b。如果a能被b整除或a加b大于1000,则输出a;否则输出b。
具体代码:
package com.etc.c0725.ui;
import java.util.Scanner;
public class Work1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入两个数");
System.out.print("a为:");
int a = sc.nextInt();
System.out.print("b为:");
int b = sc.nextInt();
if ((a % b == 0) || (a + b > 1000)) {
System.out.println(a);
} else {
System.out.println(b);
}
}
}
运行截图:
作业2:抽奖规则:会员号的百位数字等于产生的随机数字即为幸运会员。
具体代码:
package com.etc.c0725.ui;
import java.util.Scanner;
public class Work2 {
public static void main(String[] args) {
System.out.println("我行我素购物管理系统>幸运抽奖");
Scanner sc = new Scanner(System.in);
int a = 7;
System.out.println("请输入4位会员号:");
int b = sc.nextInt();
int c = b / 100 % 10;
if (a == c) {
System.out.println(b + "号客户是幸运用户,获得精美MP3一个。");
} else {
System.out.println(b + "号客户,谢谢您的支持!");
}
}
}
运行截图:
作业3:
需求说明: 普通顾客购物满100元打9折;会员购物打8折;会员购物满200元打7.5折
实现思路: 1、外层判断是否是会员
2、内层判断是否达到 ,相应打折要求 难点指导: 嵌套if选择结构 中{ }的使用
具体代码:
package com.etc.c0725.ui;
import java.util.Scanner;
public class Work3 {
public static void main(String[] args) {
System.out.println("请输入是否是会员:是(y)/否(其他字符)");
Scanner sc = new Scanner(System.in);
String answer = sc.next();
System.out.print("请输入购物金额:");
double m = sc.nextInt();
if (answer.equals("y")) { // 会员
if (m >= 200) {
double b = m * 0.75;
System.out.println("您是会员");
System.out.println("实际支付:" + b);
} else {
double e = m * 0.8;
System.out.println("您是会员");
System.out.println("实际支付:" + e);
}
} else if (m >