Eclipse keeps giving me the following error:
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?
I’ve tried looking through Google and Bing, and I’ve double checked my Java examples book, but I could not work this out.
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");
}
}
Ifdoes not have a large capIin java: it should beif.