import java.util.*;
import java.Scanner.*;
class public Prismatic{
public static void main(String args[]){
Scanner s = new Scanner();
int a = s.nextInt();
}
}
沒有static的error
c:\Documents\Prismatic.java:4: error: <identifier> expected
class public Prismatic{
^
c:\Documents\Prismatic.java:4: error: <identifier> expected
class public Prismatic{
^
2 errors
原因 :
Scanner是在util底下, 所以應該要寫 import java.util.Scanner.
import java.util.*;
public class Prismatic{
public static void main(String args[]){
Scanner s = new Scanner(System.in);
int a = s.nextInt();
if(a%2==0){
System.out.println("Please, input the odd number");
}else{
for(int i = 1; i <= a ; i+=2 ){
for(int j = 1 ; j <= (a-i)/2 ; j++){ // 前面的空格
System.out.print(" ");
}
for(int j = 1 ; j <= i ; j++){ //後面要顯示的點
System.out.print("*");
}
System.out.print("\n");
}
----------------------------------------------------------------------上半部分
for(int i = a-2; i >= 1 ; i-=2 ){
for(int k = 1 ; k <= (a-i)/2 ; k++){
System.out.print(" ");
}
for(int j = i ; j >= 1 ; j--){
System.out.print("*");
}
System.out.print("\n");
}
}
}
}
9
*
***
*****
*******
*********
*******
*****
***
*
沒有留言:
張貼留言