Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8710017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:30:53+00:00 2026-06-13T04:30:53+00:00

I got Java ArrayIndexOutOfBoundsException when getting String input in Java. Please help me. This

  • 0

I got Java ArrayIndexOutOfBoundsException when getting String input in Java. Please help me. This is my code: I edited my code to split using : it says “Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 1
at solution2.Solution.main(Solution.java:27)
“

import java.util.Scanner;

public class Solution {

public static void main(String[] args){

    Scanner scan = new Scanner(System.in);
    String str = scan.next();
    String strarr[] = str.split(",");
    String temp = strarr[0];
    String temparr[] = temp.split(".");
    String temp1 = strarr[1];
    String temparr1[] = temp.split(".");
    int x1 = Integer.parseInt(temparr[0]);
    int x2 = Integer.parseInt(temparr[1]);
    int y1 = Integer.parseInt(temparr1[0]);
    int y2 = Integer.parseInt(temparr1[1]);
    System.out.println(distance(x2,x1,y2,y1));

}

public static int distance(int x1,int y1,int x2,int y2){

    int xlen=x2-x1;
    int ylen=y2-y1;

    return (xlen+ylen)*10-(ylen*5);     

}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:30:55+00:00Added an answer on June 13, 2026 at 4:30 am

    You need to escape the dot character in the String.split() regex, otherwise any character will be matched:

    String temparr[] = temp.split("\\.");
    

    For temparr1, I think you meant to use temp1:

    String temparr1[] = temp1.split("\\.");
    

    If you are expecting double values you could use Scanner.nextDouble() instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a java.lang.StackOverflowError error. This is the code: 08-30 10:34:49.528: E/AndroidRuntime(22897): FATAL EXCEPTION:
i got java.lang.NullPointerException by using CrudRepository my project looks like this: strut2 action service
So I've got some Java code that uses Jakarta HttpClient like this: URI aURI
i got this java captcha code: http://codepaste.net/a4vxzh I want to put the image the
I've tried to run a Wicket app in an embedded Jetty, using this code:
I got some java-byte-code (so compiled java-source) which is generated in my program. Now
I got a Java method that get a String and returns boolean . I
Below is simple code, I got java.util.IllegalFormatConversionException whenever i == 0 . java.util.Random r
I got a java.lang.NullPointerException when I try to call createBitmap. Here is my code:
I was using Eclipse and I got java.lang.OutOfMemoryError: PermGen space error. In Eclipse FAQ

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.