前提・実現したいこと
mainのコメント文のところに追加したいです。
例えばnumに1が入力されたら
Ec(num).printInfo();
Ec1.printInfo();
となり,idとnameを出力するようにしたいです。
if文で追加していくしかないのでしょうか?
発生している問題・エラーメッセージ
エラーメッセージ
該当のソースコード
java
1import java.util.Scanner; 2 3public class Example_main { 4 5 public static void main(String[] args) { 6 // TODO 自動生成されたメソッド・スタブ 7 Example_class Ec1 = new Example_class(1,"山田一郎"); 8 Example_class Ec2 = new Example_class(2,"山田二郎"); 9 Example_class Ec3 = new Example_class(3,"山田三郎"); 10 Example_class Ec4 = new Example_class(4,"山田四郎"); 11 Example_class Ec5 = new Example_class(5,"山田五郎"); 12 13 Example_entry Ee = new Example_entry(); 14 Scanner sc = new Scanner(System.in); 15 System.out.print("uidを入力してください >"); 16 int num = sc.nextInt(); 17 for(int i = 0; i <= Ee.entry_ok.length; i++) { 18 if(num == Ee.entry_ok[i]) { 19 //System.out.println("Ec" + num + .printInfo();) 20 //System.out.println("〇"); 21 break; 22 } 23 else if((i+1) == Ee.entry_ok.length) { 24 System.out.println("entry_okではありません"); 25 break; 26 } 27 } 28 } 29 30}
java
1public class Example_class { 2 private int id; 3 private String name; 4 5 Example_class(int id,String name){ 6 this.id = id; 7 this.name = name; 8 } 9 10 public void printInfo() { 11 System.out.println("idは" + this.id); 12 System.out.println("nameは" + this.name); 13 }
java
1public class Example_entry { 2 int[] entry_ok = {1,3}; 3}
試したこと
System.out.println(Ec+num+.printInfo(););
補足情報(FW/ツールのバージョンなど)
Eclipse
>質問がわかりづらくてすみません。
補足情報とはそういうことではないので、言語のバージョンとか使っているフレームワークとか、開発環境を記載してください。
回答2件
あなたの回答
tips
プレビュー