Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+21 votes

When trying to run my code it gives me an error saying '.class' expected. When I put a class at the start of my code and try to run it, it tells me I don't need to add a class for this problem.

asked in CSC211_Winter2018 by (1 point)

3 Answers

+9 votes

This is probably happening because the question is asking for "bare code" and thus does not require a class. Just the code that creates whatever output you are trying to create.

answered by (1 point)
+8 votes

Could you give us the scope of this question? That would assist in providing an answer.

The error "'.class' expected" refers to an event where the compiler identifies a type name where it expects an expression and thinks you are trying to refer to that type's class object. For example, putting a main() method at the beginning of a PracticeIt question that asks for bare code returns this error, along with a slug of others:

Line 1, Column 34
'.class' expected public static void main(String[] args) {

This error can be the result of a misplaced class call, or by the fact that the problem asks for bare code-- where the `public class and main` methods aren't required. Check over the problem in question to make sure there aren't any silly mistakes.

Source: StackOverflow

answered by (1 point)
+4 votes

Have you tried doing without creating a class?

answered by (-499 points)
...