0

down vote
favorite


I have to print:

Ain't no sunshine when she's gone It's not warm when she's away. Ain't no sunshine when she's gone And she's always gone too long Anytime she goes away.

How would I used methods to print these no loops?

Would it be something like this:

public class AintNoSunshine {

public static void main (String[] args)
{
String string1 =(" Ain't no sunshine when she's gone! " );
System.out.println( string1);

String string2 = " It's not warm when she's away. ";
System.out.println( string2);

String string3 = " And she's always gone too long ";
System.out.println( string3);

String string4 = " Anytime she goes away. ";
System.out.println( string4);

}
}

Thank you.

Yes, your code is correct. You are using the `println` method from the `System.out` object to print each line of the lyrics. By calling `println` multiple times, you print each line one by one. Here's an breakdown of your code:

```java
public class AintNoSunshine {
public static void main (String[] args) {
String string1 = "Ain't no sunshine when she's gone! ";
System.out.println(string1);

String string2 = "It's not warm when she's away. ";
System.out.println(string2);

String string3 = "And she's always gone too long ";
System.out.println(string3);

String string4 = "Anytime she goes away. ";
System.out.println(string4);
}
}
```

When you run this code, it will print each line one after the other.