前提・実現したいこと
ここに質問の内容を詳しく書いてください。
(例)PHP(CakePHP)で●●なシステムを作っています。
■■な機能を実装中に以下のエラーメッセージが発生しました。
jevaで以下のようなプログラムを作りたいのですが
$ javac Lesson13_1.java$ java Lesson13_1
this.array[0] = a
this.array[1] = b
this.array[2] = c
this.array[3] = d
this.array[4] = e
this.array[5] = f
this.array[6] = g
this.array[7] = ARRAY-7
========= Result =========!
Searched the Number !
b found!!
b : Index Number is 1
h not found...
h : Index Number can not be found.
c found!!
c : Index Number is 2
発生している問題・エラーメッセージ
エラーメッセージの解決法がわかりません。
エラーメッセージ
Lesson13_1.java:28: エラー: シンボルを見つけられません
if(ta.search(check.get(i)) != -1){
^
シンボル: メソッド search(String)
場所: タイプStringArrayの変数 ta
Lesson13_1.java:30: エラー: シンボルを見つけられません
System.out.println(String.format(check.get(i) + " : Index Number is " + ta.search(check.get(i))));
^
シンボル: メソッド search(String)
場所: タイプStringArrayの変数 ta
エラー2個
該当のソースコード
public class Lesson13_1{
public static void main(String[] args){
StringArray ta = new StringArray(8);
for(int i = 0; i < ta.length; i++){
ta.set("ARRAY-" + i, i);
}
ta.set("a", 0); ta.set("b", 1); ta.set("c", 2); ta.set("d", 3); ta.set("e", 4); ta.set("f", 5); ta.set("g", 6); ta.printAll(); StringArray check = new StringArray(4); check.set("b", 0); check.set("h", 1); check.set("c", 2); check.set(temp,3); System.out.println("========= Result ========="); System.out.println("! Searched the Number !"); for(int i = 0; i < check.length; i++){ if(ta.search(check.get(i)) != -1){ System.out.println(String.format(check.get(i) + " found!!")); System.out.println(String.format(check.get(i) + " : Index Number is " + ta.search(check.get(i)))); } else { System.out.println(String.format(check.get(i) + " not found...")); System.out.println(String.format(check.get(i) + " : Index Number can not be found.")); } } System.out.println("=========================="); }
}
public class StringArray {
// -- フィールド
private String[] array;
public final int length;
// -- コンストラクタ
private StringArray() {
this.length = 0;
}
public StringArray(int size) { this.length = size; this.array = new String[this.length]; } // -- メソッド // array[index] = obj public boolean set(String obj, int index) { if (index < 0 || index > this.length - 1) { // throw new ArrayIndexOutOfBoundsException(); System.out.println("ArrayIndexOutOfBoundsException"); return false; } this.array[index] = obj; return true; } // array の index 番目の要素を返す public String get(int index) { if (index < 0 || index > this.length - 1) { System.out.println("ArrayIndexOutOfBoundsException"); return null; } return this.array[index]; } // 配列の全要素を表示 public void printAll() { for (int i = 0; i < this.array.length; i++) { System.out.println("this.array[" + i + "] = " + this.array[i]); } System.out.println(); } public String toString() { StringBuffer sb = new StringBuffer(); int i = 0; for (String s : this.array) { sb.append("this.array[" + (i++) + "] = " + s + "\n"); } return sb.toString(); } public int Search(String str){ if(str.equals(this.array.length)) { return -1; } return -1; }
}
ソースコード java
試したこと
変数名を変えたりしてみました。
補足情報(FW/ツールのバージョンなど)
見にくくて申し訳ございません。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。