+ 2
Getting an weird error....
String p="12"; int a=Integer.nextInt(p); getting this error- .nextInt(); ^illegal start of expression. getting the same error if i use Integer.valueOf(p); can anybody tell me why??
15 Answers
+ 11
Both Nathan and Palanski are right. Also, there are some little mistakes including array index range. The later part seemed complex, so I changed it in my own way. Feel free to knock if you have any question :)
https://code.sololearn.com/c0oB8rDC7kZ0/?ref=app
+ 9
By definition, a prime number shouldn't have any other divisor except 1 and the number itself. So while checking if the number is prime or not, don't check 1 and that number. That's why the loop range should be like
for (i=2; i<number; i++)
// start from 2, stop before number
Now, consider a particular number, say 12.
12's divisors: 1,2,3,4,6,12
excluding 1 and 12: 2,3,4,6
See, there's no divisor after 6 which is number/2. so we can skip the later numbers. This is not mandatory but efficient.
In your code, you're checking divisibility by 2. Instead, you have to check whether the numbers are divisible by (2.... number-1 or number/2) or not.
+ 5
Working fine here, did I miss anything?
https://code.sololearn.com/cOyy5tXFdrIS/?ref=app
+ 2
There is no Integer.nextInt() function.
nextInt() belongs to scanner class instead.
Use Integer.parseInt(p);
+ 2
use parseInt() instead of nextInt(). Your assign a string into integer that's why you get an error. Convert it into integer.
+ 2
remove public in "public int reverse1", and in your for loop there's an error. Mispelled declaration of int. It must be int j = 3 not intj = 3
+ 2
I think its the "*" that's causing the error
input number: 9 for example
when this line has been reached:
int reverse1 = Integer.parseInt(*9);
we get an error...
+ 1
Shamima Yasmin
i copied what you did but i am still getting the same illegal start of expression error.
I will share the code.
I am writing a program to find if a number is twisted prime or not eg: 167 and 761 both are primes
https://code.sololearn.com/cXwMc2Pe9IpD/?ref=app
+ 1
nextInt() is method of Scanner object you cannot call that from an Integer class
+ 1
Palanski i updated the question
+ 1
Palanski
thankx it worked.... understood my mistake
+ 1
my pleasure...
+ 1
Shamima Yasmin
in the for loop why did you do number/2.
+ 1
Shamima Yasmin
here's my updated code
why am i getting no output.
https://code.sololearn.com/cXwMc2Pe9IpD/?ref=app
0
cHiRaG GhOsH i am so sorry i made a small mistake in the question.... i used parseInt(); but still keep getting the same error....