Yes.
You can use several lines for a statement. Anywhere a space character is OK you can split a statement. This means you can't split a statement in the middle of a name, nor between the quote marks of a string literal, nor in the middle of a numeric literal. Here is the program with some statements correctly put on two lines:
class example { public static void main ( String[] args ) { long hoursWorked = 40; double payRate = 10.0, taxRate = 0.10; System.out.println("Hours Worked: " + hoursWorked ); System.out.println("pay Amount : " + (hoursWorked * payRate) ); System.out.println("tax Amount : " + (hoursWorked * payRate * taxRate) ); } }
Although correct, the division of statements is confusing to humans. It is also true that anywhere one space is OK any number of spaces are OK. Here is a better style for the program:
class example { public static void main ( String[] args ) { long hoursWorked = 40; double payRate = 10.0, taxRate = 0.10; System.out.println("Hours Worked: " + hoursWorked ); System.out.println("pay Amount : " + (hoursWorked * payRate) ); System.out.println("tax Amount : " + (hoursWorked * payRate * taxRate) ); } }
It is a good idea to indent the second half of a split statement further than the start of the statement.
Is the following correct?
cla ss example { public static void main ( String[] args ) { long hoursWorked = 40; double payRate = 10.0, taxRate = 0.10; System.out.println("Hours Worked: " + hoursWorked ); System.out.println("pay Amount : " + (hours Worked * payRate) ); System.out.println("tax Amount : " + ( hoursWorked * payRate * taxRate) ); } }