要用java写一个猜数字游戏,要求带统计功能。 20
统计功能是指最后要能报告总哦那个玩了多少局,总共猜了多少次(有几局算几局,全部的次数都加起来),最少一次猜了几次。暂时只实现了统计总共的局数。剩下的功能不知怎么办。...
统计功能是指最后要能报告总哦那个玩了多少局,总共猜了多少次(有几局算几局,全部的次数都加起来),最少一次猜了几次。
暂时只实现了统计总共的局数。剩下的功能不知怎么办。 展开
暂时只实现了统计总共的局数。剩下的功能不知怎么办。 展开
2个回答
展开全部
全局变量,写入文件中
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.util.Scanner;
class GuessNumber
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
int number, guess, guessCount;
System.out.println("Guess my number between 1 and 100");
number = (int)(100.0*Math.random()) + 1;
guessCount = 0;
while (true)
{
System.out.println("Enter your guess");
guess = kb.nextInt();
guessCount++;
if (guess == number)
break;
if (guess < number)
System.out.println("Too low");
else
System.out.println("Too high");
}
System.out.println("Right");
System.out.println("You took " + guessCount + " guesses");
System.out.println("Do you want to play again? Enter Y/N");
class GuessNumber
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
int number, guess, guessCount;
System.out.println("Guess my number between 1 and 100");
number = (int)(100.0*Math.random()) + 1;
guessCount = 0;
while (true)
{
System.out.println("Enter your guess");
guess = kb.nextInt();
guessCount++;
if (guess == number)
break;
if (guess < number)
System.out.println("Too low");
else
System.out.println("Too high");
}
System.out.println("Right");
System.out.println("You took " + guessCount + " guesses");
System.out.println("Do you want to play again? Enter Y/N");
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |