2016-02-05 60 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部分。

相關問題