arithmetic exceptions when calling method

Trying to write a simple math program that finds the prime factorial of a number. here's the code:

package pack1;

import javax.swing.JOptionPane;

publicclass PrimeFactorial{

/**

1. have user enter a whole number

2. find lowest factor of the number; put it into an array of prime factors

3. divide input number by lowest factor

4. determine if new number is prime, if so we're done, if not repeat until

the product of the division is prime.

*/

publicstaticvoid main(String[] args){

String input=JOptionPane.showInputDialog("please enter a whole number: ");

int number = Integer.parseInt(input);

PrimeFactorial jw =new PrimeFactorial();

int[] primes =newint[99];

int i = 2;

int factorFlag = 0;

int newnum;

while (number % i != 0){

i++;

}

System.out.println("the value for i is " + i);

//place first prime factor into array

primes[factorFlag] = i;

newnum = (number / i);

System.out.println("the value of newnum is " + newnum +", and the first array value is: " + primes[factorFlag]);

//reset variables

i = 2;

factorFlag++;

//determine if newnum is prime

if (jw.primeChecker(newnum)==true){

System.out.println( newnum +" is a prime number");

}else{

System.out.println( newnum +" is a prime number");

}

}

publicboolean primeChecker(int newnum){

int primeFlag=0;

for(int t=0;t<newnum;t++){

if (newnum % t == 0){

primeFlag++;

}

}

if (primeFlag == 0){

returntrue;

}else

returnfalse;

}

}

I get this error:

the valuefor i is 2

the value of newnum is 12, and the first array value is: 2

java.lang.ArithmeticException: / by zero

at pack1.PrimeFactorial.primeChecker(PrimeFactorial.java:52)

at pack1.PrimeFactorial.main(PrimeFactorial.java:41)

I'm not sure if I created the object correctly.

thanks,

bp>

[3911 byte] By [badpersona] at [2007-11-26 19:19:01]
# 1

> I get this error:

>

> the value for i is 2

> the value of newnum is 12, and the first array value

> is: 2

> java.lang.ArithmeticException: / by zero

> at

> t

> pack1.PrimeFactorial.primeChecker(PrimeFactorial.java:

> 52)

> at

> t pack1.PrimeFactorial.main(PrimeFactorial.java:41)

>

>

> I'm not sure if I created the object correctly.

> thanks,

> bp

You are trying to divide by zero on line 52

Kaj

kajbja at 2007-7-9 21:34:55 > top of Java-index,Java Essentials,New To Java...
# 2
> for(int t=0;t<newnum;t++){t starts at 0> if (newnum % t == 0){Do you know when t is 0, you're attempting to divide by 0 here?
warnerjaa at 2007-7-9 21:34:55 > top of Java-index,Java Essentials,New To Java...
# 3
ok,thanks, I'll intitialize "t" at one and see what that does. bp
badpersona at 2007-7-9 21:34:55 > top of Java-index,Java Essentials,New To Java...
# 4

After reviewing your code I found the root cause

for(int t=0;t<newnum;t++){

if (newnum % t == 0)

{

primeFlag++;

}

}

First time when the control will enter inside the for loop

Newnum will be divided by zero that will create java.lang.ArithmeticException

change the logic..... will work.>

--san--a at 2007-7-9 21:34:55 > top of Java-index,Java Essentials,New To Java...
# 5
> After reviewing your code I found the root causeYou're late to the party.
warnerjaa at 2007-7-9 21:34:55 > top of Java-index,Java Essentials,New To Java...