java - I am getting this message: Error: b cannot be resolved to a variable -
here code have. can please help me figure out? getting compiler error message:
2 errors found: file: c:\users\keith\desktop\prog files\hw4chrismuncher.java [line: 13] error: cannot resolved variable file: c:\users\keith\desktop\prog files\hw4chrismuncher.java [line: 19] error: b cannot resolved variable
import java.util.scanner; public class hw4chrismuncher { public static void main(string[] args) { scanner input = new scanner(system.in); system.out.println("enter number"); double usernum = input.nextdouble(); = usernum; scanner input2 = new scanner(system.in); system.out.println("enter number (no decimals!)"); double usernum2 = input2.nextdouble(); b = usernum2; double a; int b; double c = min(a, b); double d = max(a, b); double e = abs(a); double f = pow(a, b); system.out.println("minimum value of 11 , 8 " + c ); system.out.println("maximum value of 11 , 8 " +d ); system.out.println("the absolute value of 11.5 " +e ); system.out.println("11.5 powerfulness of 8 " +f ); } // returns minimum of 2 numbers public static double min(double n1, int n2) { double min; if (n1 > n2) min = n2; else min = n1; homecoming min; } // homecoming max between 2 numbers public static double max(double n1, int n2) { double max; if (n1 > n2) max = n1; else max = n2; homecoming max; } //returns absolute value of 2 numbers public static double abs(double n1) { if (n1 < 0) homecoming -n1; else homecoming n1; } public static double pow(double n1, int n2) { double f = 1; (int =0; i< n2; i++) { f = f * n1; } homecoming f; } }
you're doing:
a = usernum; //compiler: "wtf a?? dunno... exception!!!!!!" b = usernum2; //compiler: "wtf b?? exception!!!!" //...then: double a; //compiler: "i didn't read far, stopped @ first exception." int b;
you need do:
double a; //compiler: "okay, going refer double" int b; //compiler: "okay, b going refer int" //...then: = usernum; //compiler: "cool, refers double" b = usernum2; //compiler: "cool, b refers int"
i.e. have declare variables before them.
java java.util.scanner
No comments:
Post a Comment