標題:
資料輸入 (四) - Scanner 類別
[打印本頁]
作者:
tonyh
時間:
2020-1-31 13:13
標題:
資料輸入 (四) - 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-1-31 13:37
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-1-31 13:38
import java.util.Scanner;
public class hello {
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);
}
}
複製代碼
作者:
邱翊博
時間:
2020-1-31 13:38
package hello;
import java.util.Scanner;
public class hello {
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.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);
}
}
複製代碼
作者:
蘇宜貞
時間:
2020-1-31 13:38
import java.util.Scanner;
public class Ch01 {
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);
}
}
複製代碼
作者:
黃煜城
時間:
2020-1-31 13:39
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);
}
}
複製代碼
作者:
張宸翔
時間:
2020-1-31 13:39
import java.util.Scanner;
public class Ch43 {
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.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);
}
}
複製代碼
作者:
蔡承翰
時間:
2020-1-31 13:40
import java.util.Scanner;
public class Ch43 {
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);
}
}
複製代碼
作者:
劉家銘
時間:
2020-1-31 13:42
import java.util.Scanner;
public class Ch43 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
String str1, str2;
int x;
float y;
System.out.println("請輸入一字串(帶空白): ");
str1=s.nextLine();
System.out.println(str1);
System.out.println("請輸入一字串(不帶空白):");
str2=s.next();
System.out.println(str2);
System.out.println("請輸入一整數");
x=s.nextInt();
System.out.println("請輸入一浮點數");
y=s.nextFloat();
System.out.println(y);
}
}
複製代碼
作者:
何蕙妘
時間:
2020-1-31 13:42
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.print(a);
System.out.print("請輸入一浮點數: ");
b=s.nextFloat();
System.out.print(b);
}
}
複製代碼
作者:
陳梓瑜
時間:
2020-1-31 13:43
import java.util.Scanner;
public class Ch11 {
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-1-31 13:44
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-1-31 13:57
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-1-31 14:09
本帖最後由 蘇行一 於 2020-1-31 14:10 編輯
import java.util.Scanner;
public class Ch09 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
float score;
String str;
System.out.print("輸入你的成績: ");
score=s.nextFloat();
if(score>=90 && score<=100)
str="優";
else if(score>=80 && score<90)
str="甲";
else if(score>=70 && score<80)
str="乙";
else if(score>=60 && score<70)
str="丙";
else if(score>=0 && score<60)
str="丁";
else
str="輸入錯誤";
System.out.println(str);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2