I am currently having an issue with coding Java through MyProgrammingLab.
This is the question: Write a single statement that will print the message "first is " followed by the value of first, and then a space, followed by "second = ", followed by the value of second. Print everything on one line and go to a new line after printing. Assume that first has already been declared as a double and that second has been declared as an int. Assume also that the variables have already been given values.
So far, this is my answer:
System.out.println("first is " + first + " first.");
System.out.println("");
System.out.println("second = " + second + " second.");
Whenever I submit, the only error it gives me is:
⇒ Correct solutions that use "second = " almost certainly also uses " "
Whatever that means... I feel like I am missing something so simple, could anybody help me here?
This question has below main parts: -
1. We first need to print "first is" then value, then space and then "second is" and then value of second.
2. Complete answer should be of one line.
3. After the answer it should move to next line.
Now println() function prints everything on one line and move to next line after printing it so we can use this function.
Your correct answer will be: -
System.out.println("first is "+first+" "+"second = "+second);
In this way you can print the complete answer in one line.
Above statement can also be written as: -
System.out.println("first is "+first+" second = "+second);
Get Answers For Free
Most questions answered within 1 hours.