java 该类型的方法 If(boolean) 未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11904856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The method If(boolean) is undefined for the type
提问by Minh Hoang
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.
我试过浏览谷歌和必应,我已经仔细检查了我的 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 y E là *10");
}
}
回答by assylias
If
does not have a large cap I
in java: it should be if
.
If
I
在 Java中没有大上限:它应该是if
.
回答by kosa
if (cantim == 'F')
it should be small i
if (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"
语句而不是新方法。
回答by zie1ony
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");
}