Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+12 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 (520 points)

3 Answers

+3 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 (3.7k points)
+1 vote

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.8k points)
–1 vote

Have you tried doing without creating a class?

answered ago by (2.6k points)
...