2014-06-14 4 views
-1

는 그것은 알고리즘으로 클래스이며, 내가 N = 8JAVA 프로그램을 컴파일 할 수 없습니다. 나는 출력을 필요로 할 때 N = 8

import java.io.*; 
public class Algorithm 
{ 
    public static void main(String args[]) 
    { 

     int i,j,n; 
     String s = in.readLine(); 
     n = Integer.parseInt(s); 
     i = 2; 
     while(i<= n) 
     { 
      for(j=1; j<= n/2; j++) 
      System.out.println(i + " "+j) 
      System.out.println(i + " " +j); 
      i = i+2; 
     } 
     for (j =0; j<= i ; j+=4) 
     System.out.println(" "+j); 
    } 
} 
+1

는' – CMPS

+0

in' 나는 두 번 실수로 그 라인을 쓴 첫 번째에 println가 될 생각하지 않습니다. 여전히 코드가 작동하지 않습니다. – cseabdul92

+0

@Amir, 저는 이것이 교수님이 작성한 코드라는 것을 알았습니다. 출력을 찾으려고 노력 중입니다. 어느 쪽이든 – cseabdul92

답변

1

이 같은 시도 할 때이 프로그램의 출력을 좀하고 싶습니다 :

import java.util.Scanner; 

public class Algorithm { 
    public static void main(final String args[]) { 

     int i, j, n; 
     final Scanner scanner = new Scanner(System.in); 
     try { 
      String s = scanner.nextLine(); 
      n = Integer.parseInt(s); 
      i = 2; 
      while (i <= n) { 
       for (j = 1; j <= n/2; j++) { 
        System.out.println(i + " " + j); 
       } 
       System.out.println(i + " " + j); 
       i = i + 2; 
      } 
      for (j = 0; j <= i; j += 4) { 
       System.out.println(" " + j); 
      } 
     } finally { 
      scanner.close(); 
     } 
    } 
} 
0

이 작동합니다 : 사용자가 정의한 않았다

import java.io.*; 
public class Algorithm 
{ 
    public static void main(String args[]) 
    { 

     int i,j,n; 
     BufferedReader in = null; 
     try 
     { 
      in = new BufferedReader(new InputStreamReader(System.in)); 
      String s = in.readLine(); 
      n = Integer.parseInt(s); 
      i = 2; 
      while(i<= n) 
      { 
       for(j=1; j<= n/2; j++) 
       System.out.println(i + " "+j) 
       System.out.println(i + " " +j); 
       i = i+2; 
      } 
      for (j =0; j<= i ; j+=4) 
      System.out.println(" "+j); 
     } 
     catch(IOException e) 
     { 
      e.printStackTrace(); 
     } 
     finally 
     { 
      if(in != null) 
      { 
       try 
       { 
        in.close(); 
       } 
       catch(IOException e) {} 
      } 
     } 
    } 
} 
+0

. 코드가 잘 작동합니다. – cseabdul92