9月3日 周一

This commit is contained in:
seahi 2024-09-02 22:08:20 +08:00
parent 69a9543f2f
commit ffc016ee5c
4 changed files with 85 additions and 4 deletions

View File

@ -1,2 +1,9 @@
package PACKAGE_NAME;public class Example14 {
public class Example14 {
public static void main(String[] args) {
int sum = 0;
for (int i = 1; i <= 4; i++) {
sum += i;
}
System.out.println("sum = " + sum);
}
}

View File

@ -1,2 +1,12 @@
package PACKAGE_NAME;public class Example16 {
public class Example16 {
public static void main(String[] args) {
int x = 1;
while (x <= 4) {
System.out.println("x = " + x);
if (x == 3) {
break;
}
x ++;
}
}
}

View File

@ -1,2 +1,12 @@
package PACKAGE_NAME;public class Example17 {
public class Example17 {
public static void main(String[] args) {
int x = 1;
while (x <= 4) {
System.out.println("x = " + x);
if (x == 3) {
continue;
}
x ++;
}
}
}

View File

@ -1,2 +1,56 @@
package PACKAGE_NAME;public class SuperMarket {
import java.util.Scanner;
public class SuperMarket {
/*
* 模拟商城购物小系统
* 1.用户选择商品后后台计算商品价格
* 2.使用while循环实现用户多次购买商品
*/
public static void main(String[] args) {
double cup = 18.8; //水杯价格
double apple = 12.5; //苹果价格
double banana = 15.5; //香蕉价格
int i = 0; // 用户购买的商品序列
String continueShopping = "Y"; // 是否继续购物
System.out.println("==============天津现代小卖部================");
System.out.println("1.水杯的价格为:" + cup + "");
System.out.println("2.苹果的价格为:" + apple + "");
System.out.println("3.香蕉的价格为:" + banana + "");
while (continueShopping.equals("Y")) {
Scanner sc1 = new Scanner(System.in);
System.out.println("请输入你需要购买商品的序列号:");
i = sc1.nextInt();
switch (i) {
case 1:
System.out.println("请输入你需要购买水杯的数量:");
int cupnumber=sc1.nextInt();
double cupnum=cupnumber*cup;
System.out.println("你购买了水杯"+cupnumber+"个,需要花费"+cupnum+"");
System.out.println("需要继续购买请输入Y否则输入N");
continueShopping=sc1.next();
break;
case 2:
System.out.println("请输入你需要购买苹果的数量:");
int applenumber=sc1.nextInt();
double applenum=applenumber*apple;
System.out.println("你购买了苹果"+applenumber+"斤,需要花费"+applenum+"");
System.out.println("需要继续购买请输入Y否则输入N");
continueShopping=sc1.next();
break;
case 3:
System.out.println("请输入你需要购买香蕉的数量:");
int banananumber=sc1.nextInt();
double banananum=banananumber*banana;
System.out.println("你购买了香蕉"+banananumber+"斤,需要花费"+banananum+"");
System.out.println("需要继续购买请输入Y否则输入N");
continueShopping=sc1.next();
break;
}
}
System.out.println("期待您的下次光临!");
}
}