0
Java
hey whay should be corrected in a program which shows compilation error or a exception in thread main plz tell
11 odpowiedzi
+ 9
@Deadly Robin : You just can't divide a number by 0, it throws an arithmeticException!
You could modify your code like this :
for(x=1;x<=l;x=x+1)
{if(l%x==0)
{b=b+1;
}
}
if(b==2)
System.out.println("prime no");
else
System.out.println("not a prime no.");
+ 7
You have to listen to what @luka said. Please post your code! It may happen when you try to paste your code copied from a source elsewhere (most probably StackOverflow). Better write it.
+ 5
are you using the length of a string to see if its equals that of a prime number?
+ 3
i come across complications alot with arrays and it can be as simple as a missing one of these "," ";" or somtimes it can be due to compiling diffrent types.
to be truely sure you would have to show us your code so we can to debug it
+ 3
@Deadly Robin , plz clarify your program.
+ 2
plz see this and tell.i don't know as I. a beginner
+ 2
a very much thanx.
+ 1
import java.util.*;
public class prime {
public static void main(String args[])throws Exception {
Scanner Scan = new Scanner(System.in);
String a;
int l,b=0,x;
System.out.println("enter a string");
a=Scan.nextLine();
l=a.length();
for(x=1;x<=l;x=x+1)
{
try{
if(l%x==0)
{
b=b+1;
}
}
catch(ArithmeticException e){
System.out.println(e);
}
}
if(b==2)
System.out.println("prime no");
else
System.out.println("not a prime no.");
}
}
+ 1
hey guys, what is Arithmetic Exception used for in Java?