■ 「インテル」と名前の入ったサッカーチームチェックのプログラムを作ったで〜。
試してみてや〜
package fuoriclasse;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Inter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("インテルと名のつくサッカーチームを2つ入力してください");
List<String> ans = new ArrayList<String>();
int count = 0;
for(int i=0;i<2;i++) {
String data = sc.nextLine();
ans.add(data);
}
for(String s:ans) {
if (s.matches("インテル.*")==true) {
System.out.println("インテルと名のつくチームです");
count += 1;
} else {
System.out.println("インテルと名のつかないチームです");
}
}
switch (count){
case 1:
System.out.println("1チーム、インテルの名前が入っています");
break;
case 2:
System.out.println("2チーム、インテルの名前が入っています");
break;
case 0:
System.out.println("0チーム、インテルの名前が入っています");
break;
}
}
}
[ 2021年09月12日 - 16:50 ]
【「インテル」と名前の入ったサッカーチームチェック】
このトピックへのコメント:
(09/13 - 07:12) インテル・トゥルク