This site requires JavaScript, please enable it in your browser!
Greenfoot back
jbiser361
jbiser361 wrote ...

2019/9/28

errors when compiling system.out.print

jbiser361 jbiser361

2019/9/28

#
int count = 5; System.out.print( count + “\“”); count--; System.out.println( count + “\n” ); count--; System.out.print( count + (count --); count-=2; System.out.print( “\\” count); so this thing doesn't want to compile for some reason... its giving me issues but won't help me solve any of it
danpost danpost

2019/9/28

#
int count = 5;
System.out.print( count + “\“”); // cannot add a String value to an int value
count--;
System.out.println( count + “\n” ); // cannot add a String value to an int value
count--;
System.out.print( count + (count --); // String value expected (not int value); also, ")" expected
count-=2;
System.out.print( “\\” count); // not a valid expression
In lines 2, you could use:
System.out.print(Integer.toString(count)+"\"");
// or simply
System.out.print(""+count+"\"");
Note that the first term in the expression must be of the type expected (of type String). Well, it cannot be simply of a primary type as all Object types have immediate access to the toString() method. Line 4 has the exact same issue as line 2. Line 6 not only contains an int value, in lieu of a String value, but its general syntax if wrong. You have two open parentheses, but only one close paranthesis. You could try:
System.out.print(new Integer(count)+(count--));
Line 8, finally, starts with a String value, but there no operator, "+", to concatenate count to it; like:
System.out.print("\\"+count);
All but line 8 could be fixed by simply changing line 1 to:
Integer count = 5;
jbiser361 jbiser361

2019/9/28

#
ooo thank you so much!
You need to login to post a reply.