標題:
資料輸入 (四) - Scanner 類別
[打印本頁]
作者:
tonyh
時間:
2019-7-2 14:24
標題:
資料輸入 (四) - 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);
}
}
複製代碼
作者:
宋威廷
時間:
2019-7-2 14:47
import java.util.Scanner;
public class ch01
{
public static void main(String[] args)
{
String str1,str2;
int x;
float y;
Scanner s=new Scanner(System.in);
System.out.print("請輸入一字串(含空白):");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不含空白):");
str2=s.nextLine();
System.out.println(str2);
System.out.print("請輸入一整數:");
x=s.nextInt();
System.out.println(x);
System.out.print("請輸入一浮點數:");
y=s.nextFloat();
System.out.println(y);
}
}
複製代碼
作者:
賴駿榮
時間:
2019-7-2 14:55
import java.util.Scanner;
public class ch01
{
public static void main(String[] args)
{
String str1,str2;
int x;
float y;
Scanner s=new Scanner(System.in);
System.out.print("請輸入一字串(含空白):");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不含空白):");
str2=s.nextLine();
System.out.println(str2);
System.out.print("請輸入一整數:");
x=s.nextInt();
System.out.println(x);
System.out.print("請輸入一浮點數:");
y=s.nextFloat();
System.out.println(y);
}
}
複製代碼
回復
2#
宋威廷
作者:
李從赫
時間:
2019-7-2 14:56
import java.util.Scanner;
public class Ch02
{
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.println("請輸入一浮點數: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
古昇暘
時間:
2019-7-2 14:56
import java.util.*;
public class ok {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int x;
float y;
String str1, str2;
System.out.println("Please enter a phrase: ");
str1=s.nextLine();
System.out.println(str1);
System.out.println("Please enter a phrase: ");
str2=s.nextLine();
System.out.println(str2);
System.out.print("Please enter a whole number");
x=s.nextInt();
System.out.println(x);
System.out.print("Please enter a decimal number");
y=s.nextFloat();
System.out.println(y);
}
}
複製代碼
作者:
古蕾娜
時間:
2019-7-2 14:56
import java.util.Scanner;
public class Ch01
{
private static String str1;
private static String str2;
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int a;
float b;
System.out.print("Enter a text(with spaces): ");
str1=s.nextLine();
System.out.println(str1);
System.out.print("Enter a text(without spaces): ");
str2=s.nextLine();
System.out.println(str2);
System.out.print("Enter a whole number: ");
a=s.nextInt();
System.out.println(a);
System.out.print("Enter a decimal number: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
陳致翰
時間:
2019-7-2 14:56
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.println("請輸入一字串(帶空白): ");
str1=s.nextLine();
System.out.println(str1);
System.out.println("請輸入一字串(不帶空白): ");
str2=s.next();
System.out.println(str2);
System.out.println("請輸入一整數: ");
a=s.nextInt();
System.out.println(a);
System.out.println("請輸入一浮點數:");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
蔡杰恩
時間:
2019-7-2 14:56
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.nextLine();
System.out.println(str2);
System.out.print("請輸入一整數:");
a=s.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數:");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
陳智鈞
時間:
2019-7-2 14:57
import java.util.Scanner;
public class Ch12
{
public static void main(String agrs[])
{
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.print("請輸入一整數: ");
a=s.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數: ");
b=s.nextFloat();
System.out.print(b);
}
}
複製代碼
作者:
謝宗佑
時間:
2019-7-2 14:57
import java.util.Scanner;
public class Ch12
{
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);
}
}
複製代碼
作者:
葉子于
時間:
2019-7-2 14:57
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);
}
}
複製代碼
作者:
林宥杰
時間:
2019-7-2 14:58
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.println("請輸入一字串(不帶空白): ");
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);
}
複製代碼
作者:
張啟廣
時間:
2019-7-2 14:58
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);
}
}
複製代碼
作者:
王煦
時間:
2019-7-2 14:59
import java.util.Scanner;
public class ch01
{
public static void main(String[] args)
{
String str1,str2;
int x;
float y;
Scanner s=new Scanner(System.in);
System.out.print("請輸入一字串(含空白):");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不含空白):");
str2=s.nextLine();
System.out.println(str2);
System.out.print("請輸入一整數:");
x=s.nextInt();
System.out.println(x);
System.out.print("請輸入一浮點數:");
y=s.nextFloat();
System.out.println(y);
}
}
複製代碼
作者:
李沛儒
時間:
2019-7-2 15:01
import java.util.Scanner;
public class ch01
{
public static void main(String[] args)
{
String str1,str2;
int x;
float y;
Scanner s=new Scanner(System.in);
System.out.print("請輸入一字串(含空白):");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不含空白):");
str2=s.nextLine();
System.out.println(str2);
System.out.print("請輸入一整數:");
x=s.nextInt();
System.out.println(x);
System.out.print("請輸入一浮點數:");
y=s.nextFloat();
System.out.println(y);
}
}
複製代碼
作者:
陳柏銓
時間:
2019-7-2 15:10
import java.util.Scanner;
public class Ch12 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
String str1, str2;
int x;
float y;
System.out.print("請輸入一字串(帶空白)");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白)");
str2=s.next();
System.out.println(str2);
System.out.print("請輸入一整數");
x=s.nextInt();
System.out.println(x);
System.out.print("請輸入一浮點數");
y=s.nextFloat();
System.out.println(y);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2