作业1
作业2
作业3
package com. company;
import java. util. Scanner;
public class Main {
public static void main ( String[ ] args) {
Scanner a = new Scanner ( System. in ) ;
int fw = ( int) ( Math. random ( ) * 100 + 1 ) ;
int money = 50 ;
System. out. println ( "*猜数字游戏\n*规则:初始金额50元,每猜一局10元 猜中奖励30元,每局有6次机会,数字范围0-100!" ) ;
for ( ; money >= 10 ; ) {
money - = 10 ;
System. out. println ( "\n*余额(本局已交10元):" + money) ;
System. out. print ( "*数字范围0-100!" ) ;
fw = ( int) ( Math. random ( ) * 100 + 1 ) ;
for ( int cishu = 0 ; cishu < 6 ; ) {
cishu++ ;
boolean pd = a. hasNextInt ( ) ;
if ( pd) {
int cai = a. nextInt ( ) ;
if ( cai > 0 && cai < 100 ) {
if ( cai == fw) {
System. out. println ( "*恭喜你猜中了!第" + cishu + "次猜中!奖励30元" ) ;
money + = 30 ;
cishu = 6 ;
} else if ( cai > fw) {
System. out. println ( "*大了!已用次数:" + cishu) ;
} else {
System. out. println ( "*小了!已用次数:" + cishu) ;
}
} else {
System. out. println ( "*请输入0-100!已用次数:" + cishu) ;
}
} else {
System. out. println ( "*请输入整数!已用次数:" + cishu) ;
String nazou = a. next ( ) ;
}
}
if ( money < 10 ) {
System. out. println ( "*余额不足!游戏结束!" ) ;
}
}
}
}