如何重复字符串方法

时间:2015-09-27 00:47:28

标签: string

我必须打印:

她离开时没有阳光 她离开时不温暖。 她离开时没有阳光 而且她总是走得太久 她随时离开。

我如何使用方法打印这些无循环?

会是这样的:

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);


   }
 }

谢谢。

1 个答案:

答案 0 :(得分:0)

你写的代码看起来很好,你有任何错误吗?如果将所有打印线移到底部,它看起来会更清晰一些:

public class AintNoSunshine {

public static void main (String[] args) 
{
  String string1 =(" Ain't no sunshine when she's gone! "  );
  String string2 = " It's not warm when she's away. ";
  String string3 = " And she's always gone too long ";
  String string4 = " Anytime she goes away. ";
  System.out.println( string1);
  System.out.println( string2);
  System.out.println( string3);
  System.out.println( string4);
 }
}