標題:
資料輸入 (四) - Scanner 類別
[打印本頁]
作者:
tonyh
時間:
2021-1-22 13:27
標題:
資料輸入 (四) - 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);
}
}
複製代碼
作者:
吳聲寬
時間:
2021-1-22 13: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("Enter a sentence with space: ");
str1=s.nextLine();
System.out.println(str1);
System.out.print("Enter a sentence without space: ");
str2=s.next();
System.out.println(str2);
System.out.print("Enter a integer number: ");
a=s.nextInt();
System.out.println(a);
System.out.print("Enter a float number: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
王博裕
時間:
2021-1-22 14: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);
}
}
複製代碼
作者:
楊澤全
時間:
2021-1-22 14:02
import java.util.Scanner;
public class Ch02
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
String str1,str2;
System.out.print("請輸入一字串(帶空白):");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白):");
str2=s.next();
System.out.println(str2);
System.out.println("請輸入一整數:");
int a=s.nextInt();
System.out.println(a);
System.out.println("請輸入一小數:");
float b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
王睿宇
時間:
2021-1-22 14:03
import java.util.Scanner;
public class A {
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);
}
}
複製代碼
作者:
李柏穎
時間:
2021-1-22 14:03
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);
}
}
複製代碼
作者:
卓炘暘
時間:
2021-1-22 14:04
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("Enter a sentence with space: ");
str1=s.nextLine();
System.out.println(str1);
System.out.print("Enter a sentence without space: ");
str2=s.next();
System.out.println(str2);
System.out.print("Enter a integer number: ");
a=s.nextInt();
System.out.println(a);
System.out.print("Enter a float number: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
紀承典
時間:
2021-1-22 14:05
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.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);
}
}
複製代碼
作者:
楊小萱
時間:
2021-1-22 14:07
import java.util.Scanner;
public class Ch05
{
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);
}
}
複製代碼
作者:
藍健洲
時間:
2021-1-22 14:14
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://istak.org.tw/seed/)
Powered by Discuz! 7.2