Online Course Discussion Forum

AP CS A question about FRQ

 
 
Picture of Maiya Qiu
AP CS A question about FRQ
by Maiya Qiu - Tuesday, April 25, 2023, 6:48 AM
 

Hello everyone, my question is pretty simple I've been doing AP CS A free response and sometimes it has long names for variables and in the end i cant really write what is supposed to be one line of code in one line. Do I just keep writing in the next line? Doesn't feel right to do that.


 
Picture of Dr. Kevin Wang
Re: AP CS A question about FRQ
by Dr. Kevin Wang - Tuesday, April 25, 2023, 12:34 PM
 

In Java source code, the line break, tab, and the space characters are all treated as "white space", and don't affect syntax. So if you need to break a line in your code, there's no problem.  Just don't break up a long variable name, or a double-quoted String.  You may write 

for (int i=0; i< 100; i++) {sum += i;}

or you may write

for (
int i=0;
i < 100;
i++)
{
sum +=
i;
}

and it will be the same. How you arrange the code in a prettier way is a matter of style. A good style is easier for maintenance.  For the exam, as long as you have the correct code and correct syntax, and your code is not too messy in style, it should be okay.