0

Java

hey whay should be corrected in a program which shows compilation error or a exception in thread main plz tell

18th Oct 2017, 7:33 AM
Shubh Mehrotra
Shubh Mehrotra - avatar
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.");
18th Oct 2017, 8:02 AM
Dev
Dev - avatar
+ 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.
18th Oct 2017, 7:55 AM
Dev
Dev - avatar
+ 5
are you using the length of a string to see if its equals that of a prime number?
18th Oct 2017, 8:04 AM
D_Stark
D_Stark - avatar
+ 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
18th Oct 2017, 7:40 AM
D_Stark
D_Stark - avatar
+ 3
@Deadly Robin , plz clarify your program.
18th Oct 2017, 8:30 AM
Aaron Stone
Aaron Stone - avatar
18th Oct 2017, 7:56 AM
Shubh Mehrotra
Shubh Mehrotra - avatar
+ 2
plz see this and tell.i don't know as I. a beginner
18th Oct 2017, 7:57 AM
Shubh Mehrotra
Shubh Mehrotra - avatar
+ 2
a very much thanx.
18th Oct 2017, 9:59 AM
Shubh Mehrotra
Shubh Mehrotra - avatar
+ 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."); } }
18th Oct 2017, 10:12 AM
Bairavi Singaravelu
Bairavi Singaravelu - avatar
+ 1
hey guys, what is Arithmetic Exception used for in Java?
18th Oct 2017, 10:24 AM
Aaron Stone
Aaron Stone - avatar