Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ▪️Test115.java
- package sc;
- import java.io.*;
- //String 型の変数 s に文字列を入力し、s の値を表示するプログラムを作成しなさい。
- public class Test115 {
- // String 型変数 s に入力された1行分の文字列が得られる
- static Human h;
- static BufferedReader br;
- static String name1;
- static java.util.Scanner sc2;
- static String s6;
- public static void main(String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- java.util.Scanner sc2 = new java.util.Scanner(System.in);
- // String s6 = sc2.nextLine();
- System.out.println("あなたの名前を入力して下さい。");
- String name1 = br.readLine();// 名前入力
- h = new Human(name1);
- // Human h = new Human(name1);
- System.out.println(
- "ようこそ" + h.getName() + "さん\n あなたのポイントは" + h.point + "ポイントです\nこれから英語の問題を出します。\nポイントを集めて下さい( ´ ▽ ` )ノ");
- // String s = br.readLine();// 1行分の文字列を入力する
- // System.out.println(s);
- System.out.println("海藻は英語で?");
- String s1 = br.readLine();
- if (s1.equals("seaweed")) {
- System.out.println("正解");
- h.point++;
- } else {
- System.out.println("不正解");
- }
- System.out.println("カワハギは英語で?");
- String s2 = br.readLine();
- if (s2.equals("filefish")) {
- System.out.println("正解");
- h.point++;
- } else {
- System.out.println("不正解");
- }
- System.out.println("サバは英語で?");
- System.out.println("1:needlefish 2:seerfish 3:mackerel 4:smelt");
- // 文字列を数字に変換する
- int s3 = Integer.parseInt(br.readLine());
- if (s3 == 1) {
- System.out.println("不正解");
- } else if (s3 == 2) {
- System.out.println("不正解");
- } else if (s3 == 3) {
- System.out.println("正解");
- h.point++;
- } else {
- System.out.println("不正解");
- }
- System.out.println("ナマズは英語で?");
- String s4 = br.readLine();
- if (s4.equals("catfish")) {
- System.out.println("正解");
- h.point++;
- } else {
- System.out.println("不正解");
- }
- System.out.println("ヒラメは英語で?");
- java.util.Scanner sc = new java.util.Scanner(System.in);
- String s5 = sc.nextLine();
- if (s5.equals("flatfish")) {
- System.out.println("正解");
- h.point++;
- } else {
- System.out.println("不正解");
- }
- Test(h);
- System.out.println("あなたのポイントは" + h.point + "ポイントになりました♡₍₍ ◝(・ω・)◟ ⁾⁾♡");
- }
- static void Test(Human h) {
- // BufferedReader br = new BufferedReader(new
- // InputStreamReader(System.in));
- // java.util.Scanner sc2 = new java.util.Scanner(System.in);
- // Human h = new Human("test");
- System.out.println("マンボウは英語で?");
- String s6 = sc2.nextLine();
- if (s6.equals("sunfish")) {
- System.out.println("正解");
- h.point++;
- } else {
- System.out.println("不正解");
- }
- }
- }
- ▪️Human.java
- package sc;
- public class Human {
- private String name;
- int point;
- Human(String name) {
- this.name = name;
- this.point = 0;
- }
- public String getName() {
- return this.name;
- }
- }
- ▪️Error
- あなたの名前を入力して下さい。
- ようこそさん
- あなたのポイントは0ポイントです
- これから英語の問題を出します。
- ポイントを集めて下さい( ´ ▽ ` )ノ
- 海藻は英語で?
- 不正解
- カワハギは英語で?
- 不正解
- サバは英語で?
- 1:needlefish 2:seerfish 3:mackerel 4:smelt
- Exception in thread "main" java.lang.NumberFormatException: For input string: ""
- at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
- at java.lang.Integer.parseInt(Integer.java:592)
- at java.lang.Integer.parseInt(Integer.java:615)
- at sc.Test115.main(Test115.java:46)
Advertisement
Add Comment
Please, Sign In to add comment