2016-08-01 23 views
-1

我想構建一個圖像,我想所有的方法出來在同一行,但到目前爲止,這就是我所得到的。我無法弄清楚如何讓下一個被調用的方法出現在前一個方法旁邊的同一行/右邊。誰能幫忙?如何調用main中的方法以使它們在同一行上輸出?

public class Diamonds {  
public static void main (String [] args) throws IOException { 
    //calling the methods to put the logo together 
    triangleB(); //part of top diamond 
    triangleA(); //part of top diamond 
    triangleC(); //part of top diamond 
    triangleD(); //part of top diamond 
    triangleB(); //part of bottom left diamond 
    drawBox(); //part of bottom left diamond 
    triangleD(); //part of bottom left diamond 
    triangleC(); //part of bottom right diamond 
    drawBox(); //part of bottom right diamond 
    triangleA(); //part of bottom right diamond 

} 

public static void triangleA() throws IOException { 
    //creates top right piece of top diamond and piece of bottom right diamond 
    Scanner fileInput = new Scanner(new File("config.txt")); 

    int size = fileInput.nextInt(); 
    int y = fileInput.nextInt(); 

    while (y <= size) { 
     for (int x = 0; x <= size; x++) { 
      if (x <= y) System.out.print("*"); 
      else System.out.print(" ");} 
     y++; 
     System.out.println(); 
    } 
} 

public static void triangleB() throws IOException { 
    //creates top left piece of top diamond and piece of bottom left diamond 
    Scanner fileInput = new Scanner(new File("config.txt")); 

    int size = fileInput.nextInt(); 
    int y = fileInput.nextInt(); 

    while (y <= size) { 
     for (int x = size; x >= 0; x--) { 
      if (x <= y) System.out.print("*"); 
      else System.out.print(" ");} 
     y++; 
     System.out.println(); 
    } 
} 

public static void triangleC() throws IOException { 
    //creates bottom left piece of top diamond and piece of bottom right diamond 
    Scanner fileInput = new Scanner(new File("config.txt")); 

    int size = fileInput.nextInt(); 
    int y = fileInput.nextInt(); 

    while (y <= size) { 
     for (int x = 0; x <= size; x++) { 
      if (x >= y) System.out.print("*"); 
      else System.out.print(" ");} 
     y++; 
     System.out.println(); 
    } 
} 

public static void triangleD() throws IOException { 
    //creates bottom right piece of top diamond and piece of bottom left diamond 
    Scanner fileInput = new Scanner(new File("config.txt")); 

    int size = fileInput.nextInt(); 
    int y = fileInput.nextInt(); 

    while (y <= size) { 
     for (int x = size; x >= 0; x--) { 
      if (x >= y) System.out.print("*"); 
      else System.out.print(" ");} 
     y++; 
     System.out.println(); 
    } 
} 

public static void drawLine() throws IOException { 
    //method used to draw lines for the box 
    Scanner fileInput = new Scanner(new File("config.txt")); 

    int size = fileInput.nextInt(); 

    for (int x = 0; x < size; x++) { 
     System.out.print("**"); //two asterisks instead of one to create a box with longer length than height 
    } 
    System.out.println(); 
} 

public static void drawBox() throws IOException { 
    //method to draw a box for the bottom diamonds 
    Scanner fileInput = new Scanner(new File("config.txt")); 

    int size = fileInput.nextInt(); 
    int y = fileInput.nextInt(); 

    while (y <= size) { 
     drawLine(); 
     y++; 
    } 
} 

}

+1

使用'System.out.print',而不是'System.out.println'。 –

+0

請在您的問題中發佈您的代碼。評論中無法閱讀。 –

+0

順便說一句,這裏的目標是輸出三菱的標誌。 –

回答

0

儘量用printf()代替的println()

相關問題