Tuesday 15 July 2014

Java program only returns the input, does not show calculation result in methods -


For calculating factor, Euler number and Euler power x, I have been prepared under the "Factorial" class and the "vergate" class

When I execute the program; It gives me the same input number for each method. Is anyone advised that what is the problem, thank you very much for your kind assistance?

This is the actual category:

  The factual {public zero instruction () {System.out.printf ("Enter your choice: \ N", "1 to calculate a factual value of integers. \ N", "To calculate mathematical constant e For 2. \ N "," 3, e ^ x. \ N "," to end 4. 4); } // End of instructions // ******* A ******** Public Double Count InputValue (int n) {int ans = 1; For (int i = 1; i & lt; = n; i ++) {ans = ans * i; } Return ans; } // End method calculation InputValue // ****** b ******* Public double calculation_account_A_ value (double conditions) {double e = 1; For (Int i = 1; i & lt; terms; i ++) E = = ((double) 1 / (Count InputValue (i))); Return e; } // ******** C ********** Public double compute_ex (double rule) // method E Power x {int x = 1; Double e = 1; For (int i = 1; i & lt; terms; i ++) E + = (MathPo (X, I) / (GNU (value)); X ++; Return e; }}   

and class behavior including main:

  import java.util.Scanner; // programmable scanner uses public class behavior {Private stationary scanner input; Public static zero main (string [] args) {factual myfactorial = new factor (); Myfactorial.instructions (); System.out.printf ("?"); Int likes; Input = new scanner (System.in); Like = input.nextInt (); Switch (like) {case 1: System.out.printf ("Enter numbers for factual calculation"); Int number = 1; Number = input.nextInt (); Myfactorial.calculateInputValue (number); // If the integer is larger or 0, then print equal to "numeric:% d" (number> = 0) System.out.printf ("factorial is equal:% d \ n", number); // Otherwise, the print "input value is not valid." Else System.out.printf ("Error: input value is not valid. \ N"); break; Case 2: System.out.printf ("Enter the number of words to calculate e continuity. \ N"); Number = input.nextInt (); Myfactorial.calculate_e_value (number); System.out.printf ("e value% 2d \ n", is the number); break; Case 3: System.out.printf ("Enter x value of X. stability. \ N"); Number = input.nextInt (); Myfactorial.compute_ex (number); System.out.printf ("e power x% 2d \ n", is the number); break; Default: myfactorial.instructions (); }}}}    

You should retrieve one method in each variable and then print it . For example:

  int val = myfactorial.calculateInputValue (number); If (Val & gt; = 0) System.out.printf ("Factorial equivalent:% d \ n", val);   

You call this method everywhere and print the returned value. This will solve your problem.

No comments:

Post a Comment