Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+20 votes
public class wrong {
  public static void main(String[] args) {
	  double y = 8.0;
	  double x = 10.01;
      double last = mystery(x,y);
	  y = 8.0;
	  System.out.println("x = "+  x +" and y = "+y);
	  mystery(x,y);
	  System.out.println("x = "+  x +" and y = "+ answer);
	  int z = 5;
	  System.out.println("z = "+z);
  }

  public static double mystery(double num1, double num2) {
	
   	 double answer= 867.5309;
	 return answer;
	
  }
}
asked in CSC211_Winter2018 by (1 point)
edited by

2 Answers

+16 votes

I think it is because you should be calling the method 'mystery' rather than 'answer', the value you returned.

answered by (1 point)
+13 votes

You do not call the variable "answer". Even though you returned answer from the method mystery, the value for "answer" is not being called in the main method thus making the value for answer float in "coding oblivion"

answered by (1 point)
...