0

This is my code :---

import java.lang.*;
class Console
{
        public static void main(String args[])
        {
            char i;
            i=System.console().readLine("this is how we give he input to the string");
            System.out.println("this is what we want to print:0)");
            System.out.println(i);

        }
}

and the output I am getting is this:-

Output:-

.java:7: cannot find symbol
symbol  : method console()
location: class java.lang.System
    i=System.console().readLine("this is how we give he input to the string");
                ^
1 error

Tool completed with exit code 1

If anyone can help me out...

skaffman
  • 398,947
  • 96
  • 818
  • 769
Vinit
  • 95
  • 2
  • 7

2 Answers2

0

Mistake with the jdk version, because it must be jdk1.6 or later, and when changed to a newer jdk, there's a compilation problem, System.console().readLine() returns a String, but you assigned char

richarbernal
  • 1,063
  • 2
  • 14
  • 32
0

Also, some IDE's have trouble with the console class (possibly because they are using it themselves to redirect output to a window/dialog)

So a really good work around is using:

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readline();
    //or if you want a char
    char i = str.charAt(0);

Hope that helps