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

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

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

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

Q&A

0回答

1303閲覧

VariableDeclaratorIdエラーについて

jeterdx

総合スコア0

Java

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

0グッド

0クリップ

投稿2022/04/26 15:54

チューリングマシンのテープを簡易的に再現せよという課題に取り組んでおり、そのTape Classのコードが上手く動かず、ご助言いただければ幸いです。
構成としては、以下のTapeクラスがCellクラスを呼んでいます。そのほかにも関係するクラスはありますが、ここでは割愛します。

Java

1package turing; 2 3import java.util.ArrayList; 4 5public class Tape { 6// public Tape(){ 7 //Prepare cells for tape. 8 Cell cell = new Cell(); 9 ArrayList<Cell> tape = new ArrayList<Cell>() { 10 { 11 add(cell); 12 } 13 }; 14 //Start pointing the index 0 cell as a current cell and assign blank space to it. 15 Cell currentCell = tape.get(0); 16 currentCell.content = ' '; 17// } 18 //Define each method needed for tape. 19 public Cell getCurrentCell() { 20 return currentCell; 21 } 22 public char getContent() { 23 return currentCell.content; 24 } 25 public void setContent(char ch) { 26 currentCell.content = ch; 27 } 28 public void moveLeft() { 29 if (currentCell == tape.get(0)){ //Check whether the current cell is the most left of the tape or not. 30 tape.add(0, cell); //If so, add the new cell to the top of the tape and move left. 31 currentCell = currentCell.prev; 32 } else { 33 currentCell = currentCell.prev; 34 } 35 } 36 public void moveRight() { 37 if (currentCell == tape.get(tape.size()-1)){ //Check whether the current cell is the most right of the tape or not. 38 tape.add(cell); //If so, add the new cell to the last of the tape and move right. 39 currentCell = currentCell.next; 40 } else { 41 currentCell = currentCell.next; 42 } 43 } 44 public String getTapeContents() { 45 String result = null; 46 for (int i = 0; i < tape.size(); i++) { 47 result += tape.get(i).content; 48 } 49 result.trim(); 50 return result; 51 } 52}

Java

1package turing; 2 3 4/** 5 * Represents one cell on a Turing Machine tape. 6 */ 7public class Cell { 8 9 public char content; // The character in this cell. 10 public Cell next; // Pointer to the cell to the right of this one. 11 public Cell prev; // Pointer to the cell to the left of this one. 12 13}

上記のコードのうち、TapeクラスがEclipse上で、以下のエラーメッセージを吐いておりました。

Syntax error on token "content", VariableDeclaratorId expected after this token

該当箇所は、Tapeクラスの、以下の一行です。エラーメッセージを調べましたが、具体的に何がエラーの原因となっているか理解できませんでした。CellクラスのcurrentCellが持つ、contentメンバーに、空白スペースのChar型を代入したい、というのが意図です。
currentCell.content = ' ';

ご助言いただけますと幸いです。

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

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

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

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

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

dodox86

2022/04/27 00:02

Tapeクラスのコンストラクタ public Tape() { とその閉じカッコがコメント扱いになっていますが意図的なものでしょうか。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問