I am a college student and this is my first semester learning Java programming. For the past few days I've been stuck on some things when learning Java. One activity I'm stuck on for my class is this one:
Retype the statements, correcting the syntax errors.
System.out.println("Num: " + songnum);
System.out.println(int songNum);
System.out.println(songNum " songs");
Note: These activities may test code with different test values. This activity will perform two tests: the first with songNum = 5, the second with songNum = 9.
This is what I have so far:
import java.util.Scanner;
public class Errors {
public static void main (String [] args) {
int songNum;
songNum = 5;
System.out.println("Num: " + songNum);
System.out.println("5");
System.out.println("5 " + "songs");
The website we are using called Zybooks says the code above is correct for outputting:
Num: 5
5
5 songs
But I can't figure out what to do to output the same but with the number 9. I've tried doing the same 3 lines for it but it says it's not the correct way to do it. How do output both 5 and 9 for the values?
Change the 2nd and 3rd print statements to the following:
The problem was you hardcoded the value of
5within a string making it impossible to change.