Re: How can I get the input from keyboard without using swing?
- From: Knute Johnson <nospam@xxxxxxxxxxxxxxxxx>
- Date: Sun, 26 Jun 2005 19:29:45 -0700
iherage@xxxxxxxxx wrote:
I used to use c++.If you want to get input you write #include <iostream> using namespace std; int main(void) { int a,b; cout<"Please input a & b"; cin>>a>>b; count<<"what you input is a="<<a<<",b="<<b; return 0; } Can I use java to get the input from the keyboard like this without using the GUI?
Yes!
import java.io.*;
public class test2 {
public static void main(String[] args) {
try {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String str = null;
while ((str = br.readLine()) != null) {
System.out.println(str);
}
br.close();
} catch (IOException ioe) {
System.out.println(ioe);
}
}
}--
Knute Johnson email s/nospam/knute/ .
- References:
- Prev by Date: How can I get the input from keyboard without using swing?
- Next by Date: How to handle exceptions in constructor?
- Previous by thread: How can I get the input from keyboard without using swing?
- Next by thread: How to handle exceptions in constructor?
- Index(es):
Relevant Pages
|