please tell me why i'm getting this error
hello,
please tell me why i'm getting this error
D:\javafiles\Exam2.java:8: cannot find symbol
symbol : method parseInt(char)
location: class java.lang.Integer
int cell=Integer.parseInt(shap);
^
D:\javafiles\Exam2.java:17: plot(char,int) in Exam2 cannot be applied to (java.lang.String,int)
Exam2.plot("1",4);
^
D:\javafiles\Exam2.java:18: plot(char,int) in Exam2 cannot be applied to (java.lang.String,int)
Exam2.plot("0",4);
^
3 errors
Process completed.
Code java:
import java.lang.*;
import java.util.*;
public class Exam2
{
public static void plot(char shap, int iter)
{
int cell=Integer.parseInt(shap);
for(int i=0; i<iter;i++)
System.out.print(cell+" ");
}
public static void main(String [] args)
{
for(int i=0; i<4;i++)
{
Exam2.plot("1",4);
Exam2.plot("0",4);
}
}
}
Re: please tell me why i'm getting this error
Code :
import java.lang.*;
import java.util.*;
public class Exam2
{
public static void plot(char shap, int iter)
{
int cell=Character.digit(shap,10);
for(int i=0; i<iter;i++)
System.out.print(cell+" ");
}
public static void main(String [] args)
{
for(int i=0; i<4;i++)
{
Exam2.plot('1',4);
Exam2.plot('0',4);
}
}
}
you defined "shap" as character type, but you pass in a String. Use single quote for character.
Integer.parseInt takes in a String (check the API documentation ) , if you want to use a character, you can use Character class digit() method to convert a character to an integer.
Re: please tell me why i'm getting this error
OR
In case if you don't want to get lost in the world of Java API documentation, them simply change the signature of your plot method. Take String instead of a char.
Change this,
Code java:
public static void plot(char shap, int iter)
to this
Code java:
public static void plot(String shap, int iter)
This will resolve all your errors.
And one more thing, why have you imported the java.lang package?
The lang package comes inbuilt for every java class. We don't need to import it explicitly. There is nothing wrong with it, but why to add lines of code for the things which are already available? /:)
Hope that helps!
Goldest
Re: please tell me why i'm getting this error
Thank you very much Mr.JavaHater and Mr.Goldest for your help.
it works know
Re: please tell me why i'm getting this error