Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

no standard input in java?

  • 02-10-2006 7:55pm
    #1
    Closed Accounts Posts: 20,759 ✭✭✭✭


    Just started java in college. Have coded in C/C++ before.. We have to use this precoded keyboard reader which we invoke via Keyboard.readVariabletype();..

    Which means we have to drop this keyboard.java file in every directory that has a script we want to compile that requires keyboard input. This seems like a REALLY backwards way for something basic as input.

    Is there not an inherent standard input in java?


Comments

  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    import java.util.*;
    import java.io.*;
    
    public void Main()
    {
    BufferedReader standard = new BufferedReader(new InputStreamReader(System.in));
    
    // Standard.ReadLine(); and parse your input from that.
    }
    
    That should work (note: i don't know java).


  • Closed Accounts Posts: 20,759 ✭✭✭✭dlofnep


    Why are we using this backwards way in college then? :(


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Basically you have to hook yourself to the System.in stream and then parse it. Better to make it a method and read it when you need it.

    In Java 1.4.
    		InputStreamReader converter = new InputStreamReader (System.in);
    		BufferedReader in = new BufferedReader (converter);
    
    		System.out.print("Enter String: ");
    		String output = in.readLine();
    		System.out.println("*" + output + "*");
    		
    		in.close();
    		converter.close();
    

    In Java 1.5
    		Scanner scanner = new Scanner(System.in, "ISO-8859-1");
    		System.out.print("Type in a String: ");
    		String output = scanner.useDelimiter("\\r").next();
    		scanner.close();
    		
    		System.out.println("*" + output + "*");
    


  • Registered Users, Registered Users 2 Posts: 1,636 ✭✭✭henbane


    It's pretty standard in early OO courses in college. They're more interested in getting students to think about OO correctly rather than learn java's intricacies. That was the message I got in college whenever I asked similar questions.


  • Closed Accounts Posts: 20,759 ✭✭✭✭dlofnep


    Ok cheers guys, appreciated.


  • Advertisement
Advertisement