這是基本的編程,但我仍然不完全確定如何創建一個空行每隔5行。請幫忙!謝謝!在Java中,如何爲每第5行打印一個空行?
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("please enter an integer for the length");
int theLength = input.nextInt();
System.out.println("Please enter an integer for the height");
int theHeight = input.nextInt();
System.out.println("Please enter a character");
String character1 = input.next();
// int character = Integer.toString(character1);
for (int i = 0; i < theHeight; i++) { //the outer loop controls the row
for (int j = 0; j < theLength; j++) {// inner loop control
if (j % 6 != 0) { //creates a space for ever 5 character
System.out.print(character1 + " ");
} else System.out.print(" ");
}
System.out.println();
}
}
目前還不清楚你問這裏。請提供預期與實際產出,您遇到的具體問題以及您的問題的**明確**描述。 – bcsb1001
目前尚不清楚您是否試圖在每五排或每六排創建一個空間。 – shmosel
@Paula你可以看看我的解決方案。 – user3437460