Correct method form
This code does not compile.
public class Diamond {
public static void diamondOfAsterisks(String * ) {
for (int i = 1; i < 10; i += 2) {
for (int j = 0; j < 9 - i / 2; j++)
System.out.print(" ");
for (int j = 0; j < i; j++)
System.out.print("*");
System.out.print("\n");
}
for (int i = 7; i > 0; i -= 2) {
for (int j = 0; j < 9 - i / 2; j++)
System.out.print开发者_开发知识库(" ");
for (int j = 0; j < i; j++)
System.out.print("*");
System.out.print("\n");
}
}
}
Thanks
Just remove the "arguments" of your method:
public static void diamondOfAsterisks() {
....
public static void diamondOfAsterisks(String * )
That won't compile! Use a valid identifier such as star
or asterisk
The answer is this won't compile...
public static void diamondOfAsterisks(String * ) {
C++ Pointers convention don't apply in java...
精彩评论