Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

no standard input in java?

  • 02-10-2006 08: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