The Artima Developer Community
Sponsored Link

Java Answers Forum
alternative to Keyboard.cs1

2 replies on 1 page. Most recent reply: Nov 24, 2002 7:19 AM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
mike

Posts: 1
Nickname: bigmickey
Registered: Nov, 2002

alternative to Keyboard.cs1 Posted: Nov 23, 2002 3:50 PM
Reply to this message Reply
Advertisement
im trying to find how to use buffers to get the user to enter a string for processing instead of having to do

string x=keyboard.readstring()

can anyone tell me the correct sntax for this


Joyce Ann

Posts: 5
Nickname: newtoforum
Registered: Nov, 2002

Re: alternative to Keyboard.cs1 Posted: Nov 23, 2002 9:36 PM
Reply to this message Reply
string x=keyboard.readstring()

is not a standard java api. i think this is a third party. or your trying to copy the code in the book. try to create your input method for yourself. i;ll give you some pointer>

1: declare this

import java.io.*;

2: in your main method add some throw exception
public static void main(String s[])throws IOException { // begin main

3: wrap the class InputStreamReader in a BufferedReader

BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
4: use it.
System.out.println("Enter your number: " );
int number= Integer.parseInt(in.readLine());

Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: alternative to Keyboard.cs1 Posted: Nov 24, 2002 7:19 AM
Reply to this message Reply
String x= new BufferedReader(new InputStreamReader(System.in)).readLine();

Here it is in action:
This just reads one of text from the standard input (keyboard) and then prints it to standard output (screen).



import java.io.*;
class Test {
public static void main(String[] args){
try{
String x= new BufferedReader(new InputStreamReader(System.in)).readLine();
System.out.println(x);
}catch(IOException ioe){
System.err.println(ioe.getMessage());
}
}
}

Flat View: This topic has 2 replies on 1 page
Topic: a little help needed. Previous Topic   Next Topic Topic: Need Help Please

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use