0

したがって、私のブール値メソッドが実行され、正しい true または false が返されます....しかし、返されたものを取得して if ステートメントに追加するには、ある種のスキャナー関数が必要です。ここに私のメインコードがあります。どんな助けでも大歓迎です!また、カウンターが機能しません:(私は新しいです。

import java.util.Random;
import java.util.Scanner;

public class CrapsP5 {
public static void main(String[] args) {

    int number = 0, total, counter;

    total = counter = 0;
    String response;
    Scanner console = new Scanner(System. in );
    //1
    System.out.println("Would you like to play craps? (Y/N)");
    response = console.next();
    if (response.equalsIgnoreCase("N")) {
        System.exit(0);
    }
    //2       
    System.out.println("Welcome to craps. Would you like to see the rules? (Y/N)");
    response = console.next();
    if (response.equalsIgnoreCase("Y")) {
        rules();
    }
    //3 call play method

    play();
    //I need something here to act like the scanner console does?? yes?? but what?
    if (true) {

        System.out.println("Congrats! You've won!");
        counter++; //add 1 to win count (w) 
        total = counter;
        play();

    }
    if (false) {
        System.out.println("I'm sorry, you've lost.");
        System.exit(0);
    }
    //4
    System.out.println("Thanks for playing! You won " + total + " number of times before     losing.");
4

3 に答える 3

0

試す:

if(play())
{
  ....
}
else
{

}

play() がブール値を返す場合。

于 2013-02-28T06:29:19.313 に答える
0

あなたのブールメソッドはどれですか?遊ぶ()?もしそうなら

boolean result = play();
if(result){
...
}
else{
...
}

また

if(play()){
    ...
} else {
    ...
}
于 2013-02-28T06:22:47.957 に答える