转载于 : http://www.verejava.com/?id=16992623980921
import java.util.Scanner;public class Test1 {public static void main(String[] args) {// 模拟切水果游戏, 键盘输入 1:西瓜,2:香蕉,3:水蜜桃,-1:雷//输入数字打印对应的水果, 如果输入-1 终止游戏输入Scanner in = new Scanner(System.in);int num = 0; //定义了一个变量do {num = in.nextInt();//变量的生命周期if (num == 1) {System.out.println("您切到了西瓜");} else if (num == 2) {System.out.println("您切到了香蕉");} else if (num == 3) {System.out.println("您切到了水蜜桃");} else if (num == -1) {System.out.println("您切到了 雷 游戏终止");}} while (num != -1); //如果输入-1 终止游戏输入}}
转载于 : http://www.verejava.com/?id=16992623980921