Results 1 to 1 of 1
Thread: Java problem with equation
- 06-06-2013, 01:00 AM #1
Member
- Join Date
- Jun 2013
- Posts
- 1
- Rep Power
- 0
Java problem with equation
Hi i need some help with my Java code. I cant seem to get it to work. I am trying to do the birthday paradox and my code keeps messing up and giving me "NaN". Can someone please help me?
Java Code:public static void main(String []args) { int y; Scanner keyboard = new Scanner(System.in); //Scanner so we can type a custom input System.out.println("Press 1 to use the paradox. Press 2 to use the paradox extended"); //Asks you to enter your speed y = keyboard.nextInt(); //Lets the user input there speed. if(y == 1) { double n, a, p, m, k; //Initaites the variable "speed" Scanner keyboard1 = new Scanner(System.in); System.out.println("Enter the amount of people in the room"); n = keyboard.nextDouble(); //Lets the user input there speed. System.out.println("Enter the amount of days"); p = keyboard.nextDouble(); System.out.println("Enter the days again"); m = keyboard.nextDouble(); { if (m < 0) System.out.println(0.0); double fact = 1.0; while(m > 1) { fact = fact * m; m = m - 1; } System.out.println("Test value: " + fact); System.out.println("Test value: " + p); double t = (p - n); System.out.println("Test value T: " + t); if (t < 0) System.out.println(0.0); double fact1 = 1.0; while(t > 1) { fact1 = fact1 * t; t = t - 1; } System.out.println("Test again: " + fact1); double l = Math.pow(p, n); System.out.println("Test interger: " + l); double j = (fact1 * l); System.out.println("Test interger: " + j); double finish = (fact/j); System.out.println("Final value: " + finish); double testf = (finish*100); System.out.println("Test finish: " + testf); } } } }
Similar Threads
-
Need Help With Equation in Java
By Alsark in forum New To JavaReplies: 4Last Post: 02-12-2013, 05:04 PM -
converting an algebraic equation to Java
By fsuarjun03 in forum New To JavaReplies: 2Last Post: 03-09-2010, 08:58 PM -
Help with an equation in java
By coco in forum New To JavaReplies: 1Last Post: 07-31-2007, 08:47 AM -
Help with quadratic equation in java
By paul in forum New To JavaReplies: 1Last Post: 07-25-2007, 09:23 PM -
Problem with equation in my algorithm
By romina in forum New To JavaReplies: 2Last Post: 07-20-2007, 08:53 AM
Bookmarks