package com.forkeon.test;
import java.util.Scanner;
/**
- 循环
- while do...while for
- while 语法:
- do while语法:
- do{
- }
- while();
- for 循環
- break 跳出循環
- continue 結束本次循環執行下次循環
- @author Administrator
*/
public class loopdemo {
public static void main(String[] args) {
/* for (int i = 0; i < 10; i++) {
System.out.println(i);
}
String name="";// 商业名称
double price=0.0;//商品价格
int productNo=0;//商品编号
System.out.println("............");
System.out.println("请选择你要购买的商品的编号");
System.out.println("1.钢琴 2.吉他 3.键盘");
System.out.println(".............");
Scanner input=new Scanner(System.in);
String answer="y";//表示是否继续
while (answer.equals("y"))
{
System.out.println("请输入商品编号");
productNo=input.nextInt();
switch (productNo)
{
case 1:
name="钢琴";
price=20000;
break;
case 2:
name="吉他";
price=15000;
break;
case 3:
name="键盘";
price=40000;
break;
}
System.out.println(name+"....."+price);
System.out.println("是否继续(y/n)");
answer=input.next();
}
System.out.println("退出程序...");
/* int x=1;
while (x<=10) {
int y=0;
System.out.println(x);
x++;
}
System.out.println("asfsdfaf");
System.out.println("asfasf"); */
}
}