I can't get like what to do here: - void readLn() to wait for pressing enter [use readString()]

asked 09 Apr '15, 23:05

AristocratSudip's gravatar image

AristocratSudip
162
accept rate: 4%


I guess your void readLn() method should call readString() method and that's it.

link

answered 10 Apr '15, 05:40

Andrey's gravatar image

Andrey
1323
accept rate: 35%

public class ConsoleReader { public static String readString() throws Exception { Scanner cin1=new Scanner(System.in); System.out.println("Enter str:"); String str=cin1.nextLine(); return str;

    }

    public static int readInt() throws Exception
    {
        Scanner cin2=new Scanner(System.in);
        System.out.println("Enter int:");
        int n=cin2.nextInt();
        return n;//add your code here

    }

    public static double readDouble() throws Exception
    {
        Scanner cin3=new Scanner(System.in);
        System.out.println("Enter double:");
        double d=cin3.nextDouble();
        return d;//add your code here

    }

    public static void readLn() throws Exception
    {
        String str=readString();
        if(str.equals(""))
         System.out.println("success");
        else readLn();

    }
    public static void main(String args[]) throws Exception
    {
        String str=readString();
        int n=readInt();
        double d=readDouble();
        readLn();

    }

}

it is shown: Enter str: Enter int: java.util.NoSuchElementException

DONT KNOW WHAT TO DO

link

answered 25 May '15, 17:39

AristocratSudip's gravatar image

AristocratSudip
162
accept rate: 4%

you just write this String str=readString(); in your readLn() thats it .. your program will compile correctly ..

link

answered 29 Aug '16, 12:36

aliya's gravatar image

aliya
1
accept rate: 0%

My solution didn't work when I put my BufferedReader as a private static class variable. When I move it to my methods, it worked.

link

answered 12 Apr, 07:09

noelo's gravatar image

noelo
102
accept rate: 0%

public class ConsoleReader
{
    public static String readString() throws Exception
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        return reader.readLine();
    }

    public static int readInt() throws Exception
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        return Integer.parseInt(reader.readLine());
    }

    public static double readDouble() throws Exception
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        return Double.parseDouble(reader.readLine());
    }

    public static void readLn() throws Exception
    {
        ConsoleReader.readString();

    }
}
link

answered 19 May, 12:43

Igor's gravatar image

Igor
112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×1

Asked: 09 Apr '15, 23:05

Seen: 1,170 times

Last updated: 19 May, 12:43

Related questions