String[] v=s.split(" ");//it is reading only first character into v[0], But the remaining Strings are getting omitted.
ex: Consider "1 1 2011" is given as user input. It is taking v[0]=1, but
v[1] and v[2] are being empty.
Это ошибка, которую я получил.
1 1 2011
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at com.techm.Magic.main(Magic.java:15)
package com.techm;
Мой код
import java.util.Scanner;
public class Magic {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
String s=sc.next();
int h=0;
String[] v=s.split(" ");
h=(Integer.parseInt(v[0])*Integer.parseInt(v[1]));
String k=String.valueOf(h);
int len=k.length();
String d=v[2];
int y=Integer.parseInt(d);
int a=0;
if(len==1)
{
a=y%10;
if(h==a)
System.out.println("true");
else
System.out.println("false");
}
else if(len==2)
{
//d=s.substring(s.length()-2);
a=y%100;
if(h==a)
System.out.println("true");
else
System.out.println("false");
}
else
{
//d=s.substring(s.length()-3);
a=y%1000;
if(h==a)
System.out.println("true");
else
System.out.println("false");
}
}
}