java 初级while loop的错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 初级while loop的错误相关的知识,希望对你有一定的参考价值。
写了Java的一个小游戏 但是现在出了点问题 因为我输入No的时候程序没有停止 而是继续循环while loop想知道哪里出了问题
import java.util.Random;
import java.util.Scanner;
public class ChuckALuck
public static void main(String[] args)
Scanner scan = new Scanner(System.in);
Random rand = new Random(System.currentTimeMillis());
play(scan,rand);
public static void play(Scanner scanner, Random randomObject)
myMethod1(scanner,randomObject);
public static void myMethod1(Scanner scan,Random rand)
System.out.println("How much do you want to add to your bankroll?");
double Value=scan.nextInt();
boolean pt = true;
while(pt=true)
System.out.println("What is the value of your next bet($0.00-$42.54)?");
double Money=scan.nextInt();
System.out.println("Choose a number between 1 and 6:");
int ChoosedNum=scan.nextInt();
int num1 = rand.nextInt(6)+1;
int num2 = rand.nextInt(6)+1;
int num3 = rand.nextInt(6)+1;
System.out.print("Dice rolls:"+num1+" "+num2+" "+num3);
System.out.println();
double win=0.0;
if(ChoosedNum==num1&&ChoosedNum==num2&&ChoosedNum==num3)
win= Money*10;
else if(ChoosedNum==num1&&ChoosedNum==num2||ChoosedNum==num1&&ChoosedNum==num3||ChoosedNum==num2&&ChoosedNum==num3)
win=Money*2;
else if(ChoosedNum==num1||ChoosedNum==num2||ChoosedNum==num3)
win=Money;
System.out.println("Winning="+win);
if(win>0.0)
Value+=win;
else
Value-=Money;
int Count=1;
System.out.println("After bet "+Count+" your bankroll is "+Value);
System.out.print("Do you want to keep playing ");
String answer=scan.next();
if(answer.equalsIgnoreCase("Y")&&Value>0.0)
pt=true;
else
pt=false;
if(answer=="yes")
Count+=1;
== 比较
以上是关于java 初级while loop的错误的主要内容,如果未能解决你的问题,请参考以下文章