java猜数字问题_一个猜数字的游戏,有点问题,求助

一个猜数字的游戏,有点问题,求助

这是本人看完循环之后写出来的程序,有点错误改了很久没有改出来,请各位大虾帮帮忙

这是一个猜数字的游戏,数字随机产生,然后输入数字直到猜对为止。

package com.shijian.ch04;

import java.math.*;

import java.io.*;

public class Guess

{

int i,num;

char s;

public void beginG() throws java.io.IOException

{

while(true)

{

System.out.println("Do you want to play the number-guess game?");

System.out.println("(y/n)?");

s=(char)System.in.read();

//System.out.println(s);

switch(s)

{

case 'y':GuessN();

case 'n':System.exit(1);

}

}

}

public void GuessN() throws java.io.IOException

{

num=(int)(100*Math.random());

for(;;)

{

System.out.println("Please input a number between 0-100:");

System.out.print("What is it:");

do

{

i=System.in.read();

}while(i=='\n'||i=='\r');

//System.out.println(i);

if(i==num)

{

System.out.println("you are talent");

break;

}

else

{

if(i

{

//System.out.println("the "+i+" is lower than "+num+",try it again");

System.out.println("the "+i+" is lower than the nummber,try it again");

continue;

}

else

{

//System.out.println("the "+i+" is larger than "+num+",try it again");

System.out.println("the "+i+" is larger than the number,try it again");

continue;

}

}

}

}

}

package com.shijian.ch04;

import java.io.*;

public class TestGuess

{

public static void main(String args[]) throws java.io.IOException

{

System.out.println("Welcome to the game");

Guess g;

char s;

while(true)

{

g=new Guess();

g.beginG();

System.out.println("Would you like to play it again?");

s=(char)System.in.read();

switch(s)

{

case 'y':continue;

case 'n':System.exit(1);

}

}

}

}

谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值