2012-08-10 3 views
-2

이클립스 나에게 다음과 같은 오류를주는 유지 유형에 대해 정의되지 않는다 : 나는 이것을 이해하지방법의 경우는 (부울)는

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
input cannot be resolved 
The method If(boolean) is undefined for the type bai1DinhLuatCuLong 
Syntax error, insert ";" to complete Statement 
F cannot be resolved to a variable 

. 수정해야 할 부분은 무엇입니까? If() 기능을 사용할 수없는 이유는 무엇입니까?

Google과 Bing을 통해 살펴 보았습니다. 자바 예제 책을 두 번 확인했지만 시도 할 수 없었습니다.

import java.util.Scanner; 


public class bai1DinhLuatCuLong 
{ 
    public static void main(String[] args) 
    { 
    System.out.print("Giá trì cần tìm (F // q // r) : "); 
    char cantim = input.nextChar(); 

      // HERE THIS IS WHERE I PUT THE IF STATEMENT !!! 
    If (cantim == 'F') { 

     Scanner input = new Scanner(System.in); 
     System.out.print("Độ lớn của điện tích thứ nhất : "); 
     double q1 = input.nextDouble(); 
     System.out.print("Độ lớn của điện tích thứ hai : "); 
     double q2 = input.nextDouble(); 
     System.out.print("Khoảng cách giữa 2 điện tích : "); 
     double r = input.nextDouble(); 
     System.out.print("Hệ số k sẽ tự động được đặt là 9*10^9 như trong hệ SI"); 
     double F = 9 * Math.pow(10,9) * Math.abs(q1) * Math.abs(q2)/Math.pow(r,2); 
    } 

    System.out.print("Độ lớn lực tương tác giữa 2 điện tích điểm : " + "\n Lưu ý E là *10"); 

    } 
} 
+5

경우 중요한. 'If'를 사용할 수없는 경우 ** 'if'여야합니다 – pb2q

+0

IDE에서 강조 표시된 코드에서 'If'는 다른 키워드와 같은 색상이 아니며 'public'과 비교됩니다. 'static'은'Scanner'와'System'과 같은 색입니다. –

+0

아마도이 질문을 삭제하고 싶지 않을 것입니다 - 앞으로 누군가를 도울 수 있습니다. 대답의 점수 아래에있는 틱을 클릭하여 아래의 정답을 수락하십시오. – Edd

답변

12

If에는 큰 뚜껑이 없습니다 I : if이어야합니다.

6

if (cantim == 'F') 당신이 방법

public boolean If(boolean test) 
{ 
//Your logic. 
} 
하지만를 작성해야 i

또는

작아야합니다, 당신의 코드를 기반으로, 그것은 당신이 찾고있는 것 같다 "if" 새 메소드를 갖는 것보다.

0

는 어쩌면이 같은 것을하고 싶지 :

Scanner input = new Scanner(System.in); 
String cantim = input.next(); 

if (cantim.equals("F")) { 
    System.out.println("If F"); 
} else { 
    System.out.println("Out of F"); 
}