Welcome to the CSC Q&A.
Get help and give help!
Write great code!
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 (8 points)
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 (8 points)
+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 (8 points)
...