BlueJ and Input from keyboard

10,815

To input any value using BlueJ, I normally use the BufferedReader statement. It goes like this, BufferedReader name=new BufferedReader(new InputStreamReader(System.in)); After writing this statement in the class or the method, you can input any value using the console. Be sure to give this statement after asking for a value. In case of integers- int variable name= Integer.parseInt(name.readLine);

Share:
10,815
George V
Author by

George V

Updated on June 04, 2022

Comments

  • George V
    George V almost 2 years

    i have written the following code:

    import java.io.*;
    public class Typer
    {
        public static void main(String[] args) 
        {
           Console cons;
           cons = System.console();
           boolean edition = true;
           if(cons == null)
           {
               edition = false;
           }
           if(edition)
           {
               String name = cons.readLine("Give your name: ");
               System.out.println("Your name is: "+ name);
           }
           else
           {
               System.out.println("There is no console!");
           }
        }
     }
    

    i am using BlueJ and it doesn't prompt for an input. it just prints out there is no console! Any thougts? Thanks you!

    When i compile and run the program at powershell it runs normally. the thing is different with bluej for some reason.

  • George V
    George V over 8 years
    Thanks. I found a solution with Scanner and i finished most of the course i had with Powershell and Eclipse. Still Thanks!