-1

Eclipse 不断给我以下错误:

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,并且仔细检查了我的 Java 示例书,但我无法解决这个问题。

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");

    }
}
4

3 回答 3

12

If在 java中没有大写I:应该是if.

于 2012-08-10T15:32:06.930 回答
6

if (cantim == 'F')它应该很小i

或者

你需要写一个方法

public boolean If(boolean test)
{
//Your logic.
}

但是,根据您的代码,您似乎正在寻找"if"声明而不是拥有新方法。

于 2012-08-10T15:31:51.317 回答
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");
}
于 2012-08-10T15:44:33.433 回答