標題:
APCS - Java 高效讀取 (一)
[打印本頁]
作者:
tonyh
時間:
2022-12-17 18:41
標題:
APCS - Java 高效讀取 (一)
本帖最後由 tonyh 於 2022-12-17 20:42 編輯
由於 APCS 實作題經常有執行時間限制,因此在解 APCS 實作題時,我們盡量以 BufferedReader 元件取代 Scanner 元件進行輸入。在 Java 的環境中,BufferedReader 元件提供了更高效的讀取。
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Ch100 {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
int n;
Ch100() throws Exception
{
System.out.print("請輸入一字串(帶空白): ");
str=br.readLine();
System.out.println(str);
System.out.print("請輸入一整數: ");
n=Integer.parseInt(br.readLine());
System.out.println(n);
}
public static void main(String[] args) throws Exception{
new Ch100();
}
}
複製代碼
作者:
王秉鈞
時間:
2022-12-17 20:40
本帖最後由 王秉鈞 於 2022-12-17 20:48 編輯
import java.io.*;
public class Ch47 {
public static void main(String[] args) {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
int n;
Ch47() throws Exception
{
System.out.print("please enter a string(with white space)");
str=br.readLine();
System.out.println(str);
System.out.print("please enter an INT");
n=Integer.parseInt(br.readLine());
System.out.println(n);
}
public static void main(String[] args)throws Exception{
new Ch100();
}
}
}
複製代碼
作者:
余柏緯
時間:
2022-12-17 20:42
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class C519 {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
int n;
C519() throws IOException
{
System.out.print("請輸入一字串:");
str=br.readLine();
System.out.println(str);
System.out.print("請輸入一整數:");
n=Integer.parseInt(br.readLine());
System.out.println(n);
}
public static void main(String[] args) throws Exception
{
new C519();
}
}
複製代碼
作者:
丁肇志
時間:
2022-12-17 20:44
import java.io.*;
public class Ch100 {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n;
String str;
Ch100() throws Exception {
System.out.println("輸入一個字串(帶空白):");
str = br.readLine();
System.out.println(str);
System.out.println("輸入一個整數:");
n = Integer.parseInt(br.readLine());
System.out.println(n);
}
public static void main(String[] args) throws Exception {
new Ch100();
}
}
複製代碼
作者:
黃子倢
時間:
2022-12-17 20:44
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class P5 {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
int n;
P5() throws Exception
{
System.out.print("請輸入一字串(帶空白): ");
str=br.readLine();
System.out.println(str);
System.out.print("請輸入一整數: ");
n=Integer.parseInt(br.readLine());
System.out.println(n);
}
public static void main(String[] args) throws Exception{
new P5();
}
}
複製代碼
作者:
曾元瑜
時間:
2022-12-17 20:47
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class B1 {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
int n;
B1() throws Exception{
System.out.print("請輸入一字串(帶空白):");
str=br.readLine();
System.out.println(str);
System.out.print("請輸入一整數: ");
n=Integer.parseInt(br.readLine());
System.out.println(n);
}
public static void main(String[] args) throws Exception{
new B1();
}
}
複製代碼
作者:
張博竣
時間:
2022-12-17 20:49
import java.io.*;
public class Ch100 {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n;
String str;
Ch100() throws Exception {
System.out.println("輸入一個字串(帶空白):");
str = br.readLine();
System.out.println(str);
System.out.println("輸入一個整數:");
n = Integer.parseInt(br.readLine());
System.out.println(n);
}
public static void main(String[] args) throws Exception {
new Ch100();
}
}
複製代碼
作者:
王法棣
時間:
2022-12-17 20:50
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Ch100 {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
int n;
Ch100() throws Exception
{
System.out.println("輸入字串 :");
str=br.readLine();
System.out.println(str);
System.out.println("輸入整數 :");
n=Integer.parseInt(br.readLine());
System.out.println(n);
}
public static void main(String[] args) throws Exception {
new Ch100();
}
}
複製代碼
作者:
許志捷
時間:
2022-12-17 20:51
package lol;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Ch01 {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s;
int a;
Ch01() throws Exception
{
System.out.print("輸入一字串(帶空白): ");
s=br.readLine();
System.out.print(s+"\n請輸入一整數: ");
a=Integer.parseInt(br.readLine());
System.out.println(a);
}
public static void main(String[] args) throws Exception{
new Ch01();
}
}
複製代碼
作者:
許洧熏
時間:
2022-12-24 19:04
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Ch01 {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
int n;
Ch100() throws Exception
{
System.out.print("請輸入一字串(帶空白): ");
str=br.readLine();
System.out.println(str);
System.out.print("請輸入一整數: ");
n=Integer.parseInt(br.readLine());
System.out.println(n);
}
public static void main(String[] args) throws Exception{
new Ch01();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2