Question:
simple java program lots of errors?
2013-03-09 08:18:49 UTC
these are the errors i get

"Exception in thread "main" java.lang.Error: Unresolved compilation problems:
fnum cannot be resolved to a variable
snum cannot be resolved to a variable
answer cannot be resolved to a variable
fnum cannot be resolved to a variable
snum cannot be resolved to a variable
answer cannot be resolved to a variable

at Tutorials.main(Tutorials.java:7)"

and this is the program

import java.util.Scanner;
public class Tutorials

public static void main(String args[]) {
Scanner bucky = new Scanner(System.in);
System.out.println("Enter first num:");
fnum = bucky.nextDouble();
System.out.println("Enter second num:");
snum = bucky.nextDouble();
answer = fnum + snum;
System.out.println(answer);




}


}
Five answers:
AnalProgrammer
2013-03-09 08:23:26 UTC
fnum is not declared so has no type.

snum is not declared so has no type.

answer is not declared so has no type.



Your good at this aren't you.



Have fun.
brilliant_moves
2013-03-09 08:27:26 UTC
You didn't declare your variables! Should look like this:



import java.util.Scanner;

public class Tutorials



public static void main(String args[]) {



double fnum, snum, answer; // you have to declare your variables



Scanner bucky = new Scanner(System.in);

System.out.println("Enter first num:");

fnum = bucky.nextDouble();

System.out.println("Enter second num:");

snum = bucky.nextDouble();

answer = fnum + snum;

System.out.println(answer);



}//end main

}//end class
Silent
2013-03-09 08:25:48 UTC
Like the error message says, you're trying to use variables called fnum, snum, and answer, but you haven't declared any variables with those names.
?
2013-03-09 09:38:07 UTC
you didn't declare the variables fnum, snum and answer
2016-10-06 14:33:22 UTC
i'm extraordinarily valuable you are able to no longer contain substantial in a classification. you ought to create a separate implementation document on your classification. additionally, if Java is something like c++ you ought to end the classification brace with a semi-colon.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...