1.请输入一个数,判断这个数是偶数还是奇数,如果是偶数,请判断从1到该数是3的倍数的有哪些,如果是奇数,请判断从1到该数5的倍数有哪些;
package LianXi;
import java.util.Arrays;
import java.util.Scanner;
public class lianxi {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入一个数:");
int x = scanner.nextInt();
if (x % 2 == 0){
System.out.println("这是个偶数!");
int count = 1;
for (int a = count; a <= x; a++){
if (a % 3 == 0){
System.out.println("从1到该数是3的倍数有:" + a);
}
}
}else if (x % 1 == 0 && x != 1){
System.out.println("这是个奇数!");
int count = 1;
for (int a = count; a <= x; a++){
if (a % 5 == 0){
System.out.println("从1到该数是5的倍数有:" + a);
}
}
}
}
}
2.设计一个程序,完成(英雄)商品的购买,展示商品信息(折扣)-->输入商品价格-->输入购买数量-->提示付款-->输入付款金额-->打印购买小票(扩展);
package LianXi;
import java.util.Scanner;
public class lianxi {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double a = 30;
double b = 40;
double c = 50;
System.out.println("商品信息为:");
System.out.println("a英雄:5折!" + " " + "b英雄:4折!" + " " + "c英雄:3折!");
System.out.print("请输入要购买的英雄价格:");
double x = scanner.nextDouble();
System.out.print("请输入购买英雄数量:");
int y = scanner.nextInt();
System.out.print("请付款:");
double z = scanner.nextDouble();
if (x == a ){
double j = z - y * a * 0.5;
System.out.println("----------购物小票----------:");
System.out.println(" 您总共支付:" + z + "元");
System.out.println(" 您购买的英雄数量为:" + y + "个");
System.out.println(" 英雄价格为:" + x);
System.out.println(" 该英雄折扣为:" + "5折");
System.out.println(" 英雄最终价格为:" + a * 0.5 * y);
System.out.println(" 找零:" + j);
}else if (x == b){
double k = z - y * b * 0.4;
System.out.println("----------购物小票----------:");
System.out.println(" 您