猜价格

来源:互联网 发布:数控编程指令 编辑:程序博客网 时间:2024/04/27 02:29
import java.util.Scanner;public class app1 {Scanner input = new Scanner(System.in);public void a() {int i = (int) (Math.random() * 3) + 1;String name = null;switch (i) {case 1:name = "自行车";break;case 2:name = "小汽车";break;case 3:name = "公交车";break;}System.out.println("请猜猜" + name + "的价格:");}}

import java.util.Scanner;public class app2 {app1 q = new app1();Scanner input = new Scanner(System.in);public void a() {int s = (int) (Math.random() * 10000);for (int i = 0; i <= 3; i++) {int shu = input.nextInt(); if (shu == s) {System.out.println("恭喜你猜对了!");i=3;break;} else if(i < 3) {System.out.println("再猜一次吧");}if(shu > s && i < 2) {System.out.println("在小点!");}else if (shu < s && i < 2) {System.out.println("再大一点");}else if(i == 3) {System.out.println("4次没有猜对 下次吧");}}}}

public class app3 {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stuapp1 a=new app1();app2 b=new app2();a.a();b.a();}}

1 0