การรับข้อมูลทางจอภาพ
ในการเขียนโปรแกรมเพื่อรับข้อมูลทางจอภาพ จะต้องใช้คำสั่งthrow IOException
และ Package ชื่อ java.io
ร่วมกันเสมอ
ตัวอย่าง
import java.io.*;
class Read1 {
public static void main (String arg[]) throws IOException {
char c;
System.out.println ("กรุณาป้อนตัวอักษร 1 ตัวอักษร");
c = (char) System.in.read();
System.out.println ("ตัวอักษรที่คุณป้อนคือ " + c);
} // main
} // Read1
class Read1 {
public static void main (String arg[]) throws IOException {
char c;
System.out.println ("กรุณาป้อนตัวอักษร 1 ตัวอักษร");
c = (char) System.in.read();
System.out.println ("ตัวอักษรที่คุณป้อนคือ " + c);
} // main
} // Read1
___________
เราสามารถรับข้อมูลที่ป้อนเข้ามาทางจอภาพโดยแป้นพิมพ์ (keyboard) ได้หลายวิธี เช่น
o การใช้ System.in.read
o การใช้ BufferedReader ร่วมกับ InputStreamReader.o
Forums:
- 1535 reads