質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Q&A

1回答

1461閲覧

エラーメッセージが解決できません。

VkeX6coYU

総合スコア1

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

0グッド

1クリップ

投稿2020/06/19 06:04

前提・実現したいこと

ここに質問の内容を詳しく書いてください。
(例)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/ツールのバージョンなど)

見にくくて申し訳ございません。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

StringArrayクラスにはSearchメソッドは存在しますが、searchメソッドは在りません。
Javaは大文字と小文字を区別しますので、『シンボルを見つけられません』。

コードの貼り方について

teratailには、コードを見やすく表示する機能があります。
質問編集画面を開き、コードを選択した状態で<code>ボタンを押して下さい。
Java

投稿2020/06/19 06:22

LouiS0616

総合スコア35660

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問