如何使用BufferedReader实现以下代码?

时间:2013-10-20 20:03:16

标签: java bufferedreader

此代码用于实现掷骰子游戏。我用这个程序测试了所有其他代码,它运行得很好。首先,我通过Scanner对象在我的驱动程序中使用下面的代码块,但我的教授告诉我必须使用BufferedReader。

以下是代码:

import java.io.*;
import java.util.*;
public class Driver
{
    /*
    Dan Czarnecki
    October 8, 2013

    Class variables:
    n/a

    Constuctors:
    n/a

    Methods:
        public static void main(String[] args)
            Calls the necessary methods in the Craps class to simulate the game of craps

    Modification history:
        October 1, 2013
            Original program

        October 8, 2013
            Fixed style issues

        October 20, 2013
            Fixed more style issues
            Final version of program
    */

    public static void main(String[] args)
    {
        BufferedReader br;
        InputStreamReader isr;
        br = new BufferedReader(isr);
        int play;
        System.out.println("Would you like to play craps? (1 for yes, 0 for no)");

        play = br.nextInt();

        if(play == 1)
        {
            Craps cr;
            cr = new Craps();
            System.out.println("The value of the roll is: " + cr.roll());
        while(cr.gameOver() == false);

            cr.roll();

        }
        else
        {
            System.out.println("See you later!");
        }

    }
}

我知道我使用BufferedReader重新实现它的当前方式是错误的,所以有人能告诉我我实际上应该如何实现它吗?

1 个答案:

答案 0 :(得分:0)

多么奇怪的要求。扫描仪就是为了这种事情而发明的。

但是,现在你只能使用BufferedReader的readLine()方法,你需要将String转换为你想要获取的任何数据类型(ints等)。