2016-02-05 27 views
0

我有一个任务来编写介绍“星级”程序的方法。我已经找到了所有for循环来打印设计,但是用它们编写类是我被绊倒的地方。我对编程还很陌生,我确信我的代码中有很多愚蠢的错误。创建一个类,并为STARS程序编写方法

Here's the Document of the Stars output

public class STARS { 
    Scanner scan = new Scanner(System.in); 
    public int rows; 
    public String part1, part2, part3, part4, part5; 

    public STARS(int rows){ 
    } 

    private static String part1(int rows){ 

     for (int i = 0; i < rows; i++) { 
      for (int stars = 0; stars < rows; stars++) { 
       System.out.print("*"); 
      } 
      System.out.println(""); 
     } 
     return " "; 
    } 
    private static String part2(int rows){ 

     System.out.println(""); 
     for (int i = 1; i <= rows; i++) { 
      for (int star = 1; star <= i; star++) { 
       System.out.print("*"); 
      } 
      System.out.println(""); 
     } 
     return " "; 

    } 
+0

您的实际问题并不明显,请您说清楚一点? – tddmonkey

回答

0
public class STARS{ 

public static void main(String[] args){ 
    Scanner scan = new Scanner(System.in); 
    int rows = scan.nextInt(); 
    part1(rows); 
    part2(rows) 
} 

private static String part1(int rows){ 

for (int i = 0; i < rows; i++) { 
    for (int stars = 0; stars < rows; stars++) { 
     System.out.print("*"); 
    } 
    System.out.println(""); 
} 
return " "; 
} 

private static String part2(int rows){ 

    System.out.println(""); 
    for (int i = 1; i <= rows; i++) { 
     for (int star = 1; star <= i; star++) { 
      System.out.print("*"); 
     } 
     System.out.println(""); 
    } 
    return " "; 
    } 
} 

你真的,因为你明显地返回一个空字符串不需要的方法第1部分返回类型和第2部分。

相关问题