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

  • SEARCH
  • Home
  • 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 8798353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:04:45+00:00 2026-06-14T00:04:45+00:00

My professor asked me to do the following homework in Java, but I’m getting

  • 0

My professor asked me to do the following homework in Java, but I’m getting error while trying to execute the code.

Please take a look at the code and let me know what’s causing the error?
The code is saved into Reverse.java file.

package javaapplication44;
import java.util.Scanner;
public class Reverse {
    public static void main (String[] args) {
        String Fname[] = new String[4];
        Scanner s = new Scanner(System.in);
        for (int i=0; i<=4; i++) {
            System.out.println("\n Enter Something: ");
            Fname[i] = s.nextLine();
        }
        System.out.println ("*** The String has been Reversed ***");
        for (int i=4; i>0; i--) {
            System.out.println (Fname[i]);
        }
    }
}

error text:

Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 4
at javaapplication44.Reverse.main(Reverse.java:14)

  • 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-14T00:04:46+00:00Added an answer on June 14, 2026 at 12:04 am

    Array indexes start from zero

    change

     for (int i=0; i<=4; i++) {
    

    to

     for (int i=0; i<4; i++) {
    

    also, in your second for loop, start the loop from i=3

      for (int i=3; i>0; i--) {
    

    say if your array is of length 4, the last index would be 3.

    just remember this:

     LastINdexOfAnArray = Array_Length -1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(This is NOT a homework help question) I was asked by my professor to
So to make a long story short. A professor asked this question in class
I just took an exam where I was asked the following: Write the function
first, you would be asked to input/choose a Professor Number. then information of that
In another post ( Scala, Maven, and preprocessors ) I asked about preprocessing Java
For my Advanced Algorithms and Data Structures class, my professor asked us to pick
My professor in the uni has asked me to design a simple website with
I have been asked by my professor at university to demonstrate how load balancing
I'm new to Java and have been asked to create an applet/servlet (not sure
In one of my Java projects I am plagued by code repetition due to

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.