標題:
資料輸入 (四) - Scanner 類別
[打印本頁]
作者:
陳品肇
時間:
2019-7-2 12:36
標題:
資料輸入 (四) - 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:35
package text369;
import java.lang.System;
import java.util.Scanner;
public class text123 {
public static void main(String[] args) {
int x;
float y;
String z,k;
Scanner s=new Scanner(System.in);
System.out.println("請輸入一字串(含空白):");
z=s.nextLine();
System.out.println(z);
System.out.println("請輸入一字串(不含空白):");
k=s.next();
System.out.println(k);
System.out.println("請輸入一整數:");
x=s.nextInt();
System.out.println(x);
System.out.println("請輸入一福點數:");
y=s.nextFloat();
System.out.println(y);
}
}
複製代碼
作者:
林侑成
時間:
2019-7-2 14:38
import java.lang.System;
import java.util.Scanner;
public class asdf
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
String st1,st2;
int a;
float b;
System.out.print("請輸入一字串(帶空白): ");
st1=s.nextLine();
System.out.println(st1);
System.out.print("請輸入一字串(不帶空白): ");
st2=s.nextLine();
System.out.println(st2);
System.out.print("請輸入一整數: ");
a=s.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
黃安立
時間:
2019-7-2 14:41
package ch01;
import java.util.Scanner;
public class CHO1
{
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:42
package ch02;
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.println(a);
System.out.print("請輸入一浮點數: ");
b=s.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
呂昀宸
時間:
2019-7-2 14:50
import java.util.Scanner;
public class Nsez {
public static void main(String args[])
{Scanner z=new Scanner (System.in);
String a,b;
int c ;
float d;
System.out.print("輸入一字串(有空白)");
a=z.nextLine();
System.out.println(a);
System.out.print("輸入一字串(無空白)");
b=z.next();
System.out.println(b);
System.out.print("輸入一整數");
c=z.nextInt();
System.out.println(c);
System.out.print("輸入一浮點數");
d=z.nextFloat();
System.out.println(d);
}
}
複製代碼
作者:
蔣宗儒
時間:
2019-7-2 14:50
import java.util.Scanner;
public class junior {
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-7-2 14:54
import java.util.Scanner;
public class Ch04 {
public static void main(String args[]){
Scanner scn =new Scanner(System.in);
String str1,str2;
int a;
float b;
System.out.print("請輸入一字串(帶空白): ");
str1=scn.nextLine();
System.out.println(str1);
System.out.print("請輸入一字串(不帶空白): ");
str2=scn.next();
System.out.println(str2);
System.out.print("請輸入一整數: ");
a=scn.nextInt();
System.out.println(a);
System.out.print("請輸入一浮點數: ");
b=scn.nextFloat();
System.out.println(b);
}
}
複製代碼
作者:
潘承渙
時間:
2019-7-2 14:56
import java.lang.System;
import java.util.Scanner;
public class Ch06 {
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.print(b);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2