core java: stupid doubt

what’s wrong with this class:

class reverse
{
public static void main(String[] ar)
{
Console c=System.console();
System.out.print(“Enter the first number:”);
String n=c.readLine();
System.out.print(“Enter the second number:”);
String m=c.readLine();
int[] arr1=Integer.parseInt(n);
int[] arr2=Integer.parseInt(m);
}
}

I mean, i know string cant be parsed into an integer array… so what’s the way out??

  1. if it is a single number than you
    should do: int
    a=Integer.parseInt(m);
  2. if you want it to be first index of
    array int arr1[]=new int[10];//or
    some num
    arr1[0]=Integer.parseInt(m);
  3. if there are multiple numbers then:
    String n[]=c.readLine().split(" ");
    for(int i=0;i<n.length;i++)
    arr1[i]=Integer.parseInt(str[i]);

though its not clear what are you trying to do…

1 Like

thanks!
actually i was trying to reverse a number string.