2013-12-11 3 views
-3

나는 진위 또는 거짓 값을 인쇄하고 컴파일하는 데 어려움이 있습니다. 부울 메서드의 값을 인쇄 할 수 있습니까?클래스를 컴파일 할 수 없습니다

오류 :

javac ArrayManip.java 
ArrayManip.java:23: error: <identifier> expected 
     System.out.println(valuesSymmetrical);     ^
ArrayManip.java:23: error: <identifier> expected 
     System.out.println(valuesSymmetrical); 

public class ArrayManip 
{ 
public static void main(String [] args) 
    { 
     int numbers [] = {2,3,4,5,6,6,5,4,3,2}; 
     boolean areThey = valuesSymmetrical(numbers); 

    } 

    public static boolean valuesSymmetrical(int [] n) 
    { 
    int i = 0, y = n.length - 1; 
    while (n[i] == n[j] && i < j) 
    { 
     i++; 
     j--; 
    } 

    if (i < j) return true; 
    else return false; 
} 

    System.out.println(valuesSymmetrical); 
} 
+2

1. 당신은'에서 System.out.println (valuesSymmetrical)이 실현? 2. 메소드를 호출하려면'valuesSymmetrical (arrayOfIntegers)'와 같이 인수를 추가해야합니다. 3.'valuesSymmetrical' 메소드에서'j'는 무엇입니까? – Pshemo

+0

코드를 올바르게 형식화하기 시작하면 적절한 들여 쓰기로 문제를 쉽게 찾아야합니다. – turbo

+0

당신의 질문과 관련이 없지만, 끝 부분의'if (i j)'로 변경하고 싶습니다. –

답변

3
System.out.println(valuesSymmetrical); 

는 방법 밖에 있습니다.

다음과 같이하십시오 :

public class ArrayManip 
{ 
    public static void main(String [] args) 
    { 
    int numbers [] = {2,3,4,5,6,6,5,4,3,2}; 
    boolean areThey = valuesSymmetrical(numbers); 

    System.out.println(areThey); 

    } 

    public static boolean valuesSymmetrical(int [] n) 
    { 
    int i = 0, j = n.length - 1; // notice here you had y and not j! 
    while (n[i] == n[j] && i < j) 
    { 
     i++; 
     j--; 
    } 

    if (i < j) return true; 
    else return false; 
    } 
} 
2

당신은 실제로 전화 기능, 예를 들어, 필요,

System.out.println(valuesSymmetrical(numbers)); 

main 방법이 넣습니다.


관련없는 : 당신을 위해서, 그리고 누군가 다른 사람을 위해, 예를 들어,

public class ArrayManip { 

    public static boolean valuesSymmetrical(int [] n) { 
     int i = 0, y = n.length - 1; 
     while (n[i] == n[j] && i < j) { 
      i++; 
      j--; 
     } 

     return i < j; 
    } 

    public static void main(String args[]) { 
     int numbers[] = { 2, 3, 4, 5, 6, 6, 5, 4, 3, 2 }; 
     System.out.println(valuesSymmetrical(numbers)); 
    } 

} 

(이 어떤 논리 오류를 수정하지 않습니다.), 지속적으로 코드를 포맷하십시오

0
은 SYSOUT 위로 이동

당신의 주요 방법으로 `당신의 방법 범위의 밖에,

System.out.println(areThey); 

또는

System.out.println(valuesSymmetrical(numbers)); 
관련 문제