黑马程序员技术交流社区
标题:
我做的一个小游戏
[打印本页]
作者:
郑亚卓
时间:
2015-8-25 21:28
标题:
我做的一个小游戏
import java.util.Scanner;
class Game {
public static void main(String[]args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要玩儿的游戏的编号,游戏如下:");
show();
int num = sc.nextInt();
System.out.println("你选择玩儿的是游戏是Game" + num);
switch (num) {
case 1 :
System.out.println("请输入一个整数");
int s = sc.nextInt();
game1(s);
break;
case 2 :
System.out.println("请输入第一个整数");
int m = sc.nextInt();
System.out.println("请输入第二个整数");
int n = sc.nextInt();
game2(m,n);
break;
case 3 :
System.out.println("请输入第一个整数");
int q = sc.nextInt();
System.out.println("请输入第二个整数");
int w = sc.nextInt();
game3(q,w);
break;
case 4 :
System.out.println("请输入第一个整数");
int e = sc.nextInt();
System.out.println("请输入第二个整数");
int r = sc.nextInt();
game4(e,r);
break;
case 5:
System.out.println("请输入第一个整数");
int u = sc.nextInt();
System.out.println("请输入第二个整数");
int i = sc.nextInt();
game5(u,i);
break;
case 6:
game6();
break;
}
}
public static void show(){
System.out.println("\tGame1:输入一个数字,我给你打印对应的乘法表");
System.out.println("\tGame2:输入两个数字,我给你计算出这两个数字间的所有整数和");
System.out.println("\tGame3:输入两个数字,有意想不到的惊喜哟!!");
System.out.println("\tGame4:输入两个数字,我能猜到你心里在想什么!");
System.out.println("\tGame5:输入两个数字,你来计算着两个数字间的奇数有多少个");
System.out.println("\tGame6:我说咱俩心有灵犀你信吗?不信你输入下你最喜欢吃的水果");
}
public static void game1(int a){
for (int i = 1; i <= a;i++ ) {
for (int j = 1;j <= i ;j++ ) {
System.out.print(i + "*" + j + "=" + i*j + "\t");
}
System.out.println();
}
}
public static void game2(int a, int b){
int count =0;
for (int l = a;l <= b ;l++ ) {
count += l;
}
System.out.println(count);
}
public static void game3(int a , int b ){
a = a + b;
b = a - b;
a = a - b;
System.out.println("a=" + a + "b=" + b);
}
public static void game4(int a, int b ){
for(int x = 1; x <= a; x++){
for(int y = 1; y < x; y++){
System.out.print(" " );
}
for(int z = x; z <= a; z++){
System.out.print("* " );
}
System.out.println();
}
}
public static void game5(int a ,int b ){
int sum = 0;
for (int x = a; x <= b; x++) {
if (x%2 != 0) {
sum++;
}
}
System.out.println(sum);
}
public static void game6(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入你最喜欢吃的水果");
String fruit = sc.next();
System.out.println("美女,这么巧啊,我也喜欢吃" + fruit );
}
}
复制代码
作者:
lzfree
时间:
2015-8-25 23:12
顶一下先!
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2