標題:
資料輸入 (四) - Scanner 類別
[打印本頁]
作者:
tonyh
時間:
2020-9-4 20:40
標題:
資料輸入 (四) - Scanner 類別
利用套件 java.util 中的 Scanner 類別, 來做資料輸入.
import java.util.Scanner;
public class Ch43
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
String str1, str2;
int a;
float b;
System.out.print("請輸入一字串(帶空白): ");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白): ");
str2=s.next();
System.out.println(str2);
System.out.print("請輸入一整數: ");
a=s.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
林政瑜
時間:
2020-9-4 20:54
\import java.util.Scanner;
public class Ch43
{
public static void main(String args[])
{
Scanner s=new scanner(System.in);
String str1, str2;
int a;
float b;
System.out.print("請輸入一字串(帶空白): ");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白): ");
str2=s.next();
System.out.println(str2);
System.out.print("請輸入一整數: ");
a=s.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
李宇澤
時間:
2020-9-4 20:55
import java.util.Scanner;
public class Ch30
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
String i, j;
int a;
float b;
System.out.print("請輸入一字串(帶空白): ");
i=s.nextLine();
System.out.println(i);
System.out.print("請輸入一字串(不帶空白): ");
j=s.next();
System.out.println(j);
System.out.print("請輸入一整數: ");
a=s.nextInt();
System.out.println(a);
System.out.print("輸入一浮點數: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
孫嘉駿
時間:
2020-9-4 20:57
import java.util.Scanner;
public class Ch30
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
String str1, str2;
int a;
float b;
System.out.print("請輸入一字串(帶空白): ");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白): ");
str2=s.next();
System.out.println(str2);
System.out.print("請輸入一整數: ");
a=s.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
黃宥華
時間:
2020-9-4 20:57
import java.util.Scanner;
public class Ch87
{
public static void main(String args[])
{
int n;
float m;
String s1,s2;
Scanner c=new Scanner(System.in);
System.out.print("請輸入含空白字串");
s1=c.nextLine();
System.out.println(s1);
System.out.print("請輸入不含空白字串");
s2=c.next();
System.out.println(s2);
System.out.print("請輸入整數");
n=c.nextInt();
System.out.println(n);
System.out.print("請輸入浮點數");
m=c.nextFloat();
System.out.println(m);
}
}
複製代碼
作者:
董宸佑
時間:
2020-9-4 20:57
import java.util.Scanner;
public class Ch30
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.print("請輸入一字串(帶空白): ");
String str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白): ");
String str2=s.next();
System.out.println(str2);
System.out.print("請輸入一整數: ");
int a=s.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數: ");
float b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
夏子涵
時間:
2020-9-4 21:00
import java.util.Scanner;
public class Ch34
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
String str1, str2;
int a;
float b;
System.out.print("請輸入一字串(帶空白) : ");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白) : ");
str2=s.next();
System.out.println(str2);
System.out.print("請輸入一整數: ");
a=s.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
陳宥穎
時間:
2020-9-4 21:00
import java.util.Arrays;
import java.util.Scanner;
public class Ch30
{
public static void main(String args[])
{
Scanner g=new Scanner(System.in);
String str1 ,str2;
int a;
float b;
System.out.print("請輸入一字串(帶空白): ");
str1=g.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白): ");
str2=g.next();
System.out.println(str2);
System.out.print("請輸入一整數: ");
a=g.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數數: ");
b=g.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
劉愷鈞
時間:
2020-9-4 21:02
import java.util.Scanner;
public class Ch01
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
String str1,str2;
int a;
float b;
System.out.print("請輸入一字串(帶空白):");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白):");
str2=s.next();
System.out.println(str2);
System.out.print("請輸入一整數:");
a=s.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數:");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
沈子晏
時間:
2020-9-4 21:04
import java.util.Scanner;
public class Ch31
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
String str1, str2;
int a;
float b;
System.out.print("請輸入一字串(帶空白):");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白):");
str2=s.next();
System.out.println(str2);
System.out.print("請輸入一整數:");
a=s.nextInt();
System.out.print(a);
System.out.print("請輸入一浮點數: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
黃柏叡
時間:
2020-9-4 21:06
import java.util.Scanner;
public class Ch42
{
public static void main(String args[])
{
Scanner h=new Scanner(System.in);
String str1,str2;
int a;
float b;
System.out.print("請輸入一字串(帶空白): ");
str1=h.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白): ");
str2=h.next();
System.out.println(str2);
System.out.print("請輸入一整數: ");
a=h.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數: ");
b=h.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
黃辰昊
時間:
2020-9-11 18:45
import java.util.Scanner;
public class Ch01
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
String str1, str2;
int a;
float b;
System.out.print("請輸入一字串(帶空白)");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白)");
str2=s.next();
System.out.println(str2);
System.out.print("請輸入一整數");
a=s.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2