如果(boolean)为类型未定义的方法。

时间:2022-02-01 07:43:40

Eclipse keeps giving me the following error:

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

I do not understand this. What do I need to fix? Why can't I use the If() function?

我不明白这一点。我需要解决什么问题?为什么我不能使用If()函数?

I've tried looking through Google and Bing, and I've double checked my Java examples book, but I could not work this out.

我已经尝试过查看谷歌和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");

    }
}

3 个解决方案

#1


12  

If does not have a large cap I in java: it should be if.

如果在java中没有大写I,应该是If。

#2


6  

if (cantim == 'F') it should be small i

如果(cantim = 'F')应该是小i。

or

You need to write a method

你需要写一个方法。

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

But, based on your code, it seems you are looking for "if" statement than having new method.

但是,基于您的代码,您似乎正在寻找“if”语句,而不是使用新方法。

#3


0  

Maybe You want to do something like this:

也许你想做这样的事情:

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

#1


12  

If does not have a large cap I in java: it should be if.

如果在java中没有大写I,应该是If。

#2


6  

if (cantim == 'F') it should be small i

如果(cantim = 'F')应该是小i。

or

You need to write a method

你需要写一个方法。

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

But, based on your code, it seems you are looking for "if" statement than having new method.

但是,基于您的代码,您似乎正在寻找“if”语句,而不是使用新方法。

#3


0  

Maybe You want to do something like this:

也许你想做这样的事情:

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