標題:
資料輸入 (四) - Scanner 類別
[打印本頁]
作者:
tonyh
時間:
2019-8-2 13:09
標題:
資料輸入 (四) - 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-8-2 14:18
import java.util.Scanner;
public class Ch01 {
public static void main(String[] args) {
String str1,str2;
int a;
float b;
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("輸入一整數: ");
a=s.nextInt();
System.out.println(a);
System.out.print("輸入一浮點數: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
莊鈞程
時間:
2019-8-2 14:18
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.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-8-2 14:19
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-8-2 14:19
import java.util.Scanner;
public class ch02 {
public static void main(String[] args) {
Scanner c=new Scanner(System.in);
String str1,str2;
int a;
float b;
System.out.print("請輸入一字串(帶空白): ");
str1=c.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白): ");
str2=c.next();
System.out.println(str2);
System.out.print("請輸入一整數: ");
a=c.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數: " );
b=c.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
葉俠愷
時間:
2019-8-2 14:20
import java.util.Scanner;
public class Ch01 {
public static void main(String[] args) {
String str1,str2;
int a;
float b;
Scanner s= new Scanner(System.in);
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-8-2 14:20
import java.util.Scanner;
public class Ch02 {
public static void main(String[] args) {
int a;
float b;
String str1,str2;
Scanner s=new Scanner(System.in);
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-8-2 14:20
import java.util.Scanner;
public class Ch01
{
public static void main(String args[])
{
String str1, str2;
int a;
float b;
Scanner s=new Scanner(System.in);
System.out.print("請輸入一字串(帶空白): ");
str1=s.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白): ");
str2=s.next();
System.out.println(str2);
System.err.print("請輸入一整數: ");
a=s.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
潘憶承
時間:
2019-8-2 14:20
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-8-2 14:22
import java.util.Scanner;
public class sdf {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
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-8-2 14:23
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-8-2 14:24
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-8-2 14:24
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-8-2 14:27
本帖最後由 許育禎 於 2019-8-2 15:25 編輯
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-8-2 14:29
本帖最後由 鄭宇崴 於 2019-8-2 14:35 編輯
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-8-2 14:56
import java.util.Scanner;
import javax.sound.midi.SysexMessage;
public class Ch01 {
public static void main(String[] args) {
String str1,str2;
int a;
float b;
Scanner s=new Scanner(System.in);
System.out.print("請輸入一字串(帶空白)");
str1=s.nextLine();
System.out.print(str1);
System.out.print("請輸入一字串(不帶空白)");
str2=s.next();
System.out.print("請輸入一整數");
a=s.nextInt();
System.out.print(a);
System.out.print("請輸入一浮點數");
b=s.nextFloat();
System.out.print(b);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2