Thread View: aus.computers.java
4 messages
4 total messages
Started by Myke
Mon, 26 Jun 2000 00:00
Simple Java Input Help.
Author: Myke
Date: Mon, 26 Jun 2000 00:00
Date: Mon, 26 Jun 2000 00:00
15 lines
1085 bytes
1085 bytes
I thought it would be easy. I can do it with any other language I have had to use. All I want to do is ask a user for text input at the command line. Is this possible? I have found methods to read files, read test input from input boxes etc, but I want it in a text based interface so I do not have to worry to much about applet programming. (I am just begining) Any help would be greatly appreciated. Thanks Myke
Re: Simple Java Input Help.
Author: Greg
Date: Mon, 26 Jun 2000 00:00
Date: Mon, 26 Jun 2000 00:00
42 lines
2045 bytes
2045 bytes
Here is a small "Hello world" type program I wrote.
I hope it helps
Greg
"Myke" <myke@net2000.com.au> wrote in message
news:VGA55.50$7f7.4121@nsw.nnrp.telstra.net...
> I thought it would be easy. I can do it with any other language I have
had
> to use.
>
> All I want to do is ask a user for text input at the command line.
>
> Is this possible?
>
> I have found methods to read files, read test input from input boxes etc,
> but I want it in a text based interface so I do not have to worry to much
> about applet programming. (I am just begining)
>
> Any help would be greatly appreciated.
>
> Thanks
> Myke
>
>
begin 666 HelloText.java
M:6UP;W)T(&IA=F$N:6\N*CL-"@T*#0IC;&%S<R!(96QL;U1E>'0-"GL-"B @
M("!P=6)L:6,@<W1A=&EC('9O:60@;6%I;BA3=')I;F=;72!A<F=S*0T*(" @
M(" @("!T:')O=W,@24]%>&-E<'1I;VX-"B @("![#0H@(" @(" @("\O(&IA
M=F$N:6\N*BP@;75S="!B92!I;7!O<G1E9"!F;W(@=&AI<R!T;R!W;W)K#0H@
M(" @(" @($)U9F9E<F5D4F5A9&5R('-T9&EN(#T@;F5W($)U9F9E<F5D4F5A
M9&5R*&YE=R!);G!U=%-T<F5A;5)E861E<BA3>7-T96TN:6XI*3L@(" @(" @
M( T*(" @(" @(" -"B @(" @(" @4WES=&5M+F]U="YP<FEN="@B='EP92!Y
M;W5R(&YA;64Z(BD[#0H@(" @(" @( T*(" @(" @("!3=')I;F<@;F%M92 ]
M('-T9&EN+G)E861,:6YE*"D[#0H@(" @(" @( T*(" @(" @("!3>7-T96TN
G;W5T+G!R:6YT;&XH(DAE;&QO("(@*R!N86UE*3L-"B @("!]#0I]
`
end
Re: Simple Java Input Help.
Author: glennL
Date: Sat, 01 Jul 2000 00:00
Date: Sat, 01 Jul 2000 00:00
54 lines
1747 bytes
1747 bytes
Hi Myke,
Try this.
/**
* Read a string from the console, terminating input with a newline.
* @return The input string (null if exception).
*/
public static String readString() {
int ch = 0;
String r = "";
boolean done = false;
while (!done) {
try {
ch = System.in.read();
if (ch < 0 || (char)ch == '\n')
done = true;
else if ( (char) ch != '\r') // ignore cr
r = r + (char) ch;
}
catch(java.io.IOException e) {
done = true;
return null;
}
}
return r;
}
Cheers,
Glenn.
Myke <myke@net2000.com.au> wrote in message
news:VGA55.50$7f7.4121@nsw.nnrp.telstra.net...
> I thought it would be easy. I can do it with any other language I have
had
> to use.
>
> All I want to do is ask a user for text input at the command line.
>
> Is this possible?
>
> I have found methods to read files, read test input from input boxes etc,
> but I want it in a text based interface so I do not have to worry to much
> about applet programming. (I am just begining)
>
> Any help would be greatly appreciated.
>
> Thanks
> Myke
>
>
Re: Simple Java Input Help.
Author: Paul Murray
Date: Sun, 02 Jul 2000 00:00
Date: Sun, 02 Jul 2000 00:00
29 lines
1735 bytes
1735 bytes
"Myke" <myke@net2000.com.au> wrote in message
news:VGA55.50$7f7.4121@nsw.nnrp.telstra.net...
> All I want to do is ask a user for text input at the command line.
For that, you need to wrap a BufferedReader around System.in . Now system.in
reads raw bytes, not characters (remember, characters in java are 2-byte
unicode values), so you need to wrap system.in in a InputStreamReader first.
This means that if a person is in Japan and types in JIS keyboard escape
codes, the reader will correctly convert to japanese unicode characters.
Enter a period on a line by itself to exit the loop.
import java.io.*;
public class go {
public static void main(String[] av) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String ln;
do {
ln = br.readLine();
System.out.println(">>>" + ln + "<<<");
} while(!".".equals(ln));
}
}
--------------------------------------------------------------
http://www.users.bigpond.com/pmurray
ICQ: 26066755
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads