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 936621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:20:40+00:00 2026-05-15T21:20:40+00:00

So I’ve been practicing my Java programming skills on the CodingBat website, when I

  • 0

So I’ve been practicing my Java programming skills on the CodingBat website, when I came across this problem. In it, you have to make a simple method that takes in an array of integers of dynamic length, check to see if the elements in the array are in increasing order (1, 2, 3, 15678, etc), and return “true” if true, or “false” if there is an integer out of order.

Firstly, I initialize a boolean variable named “result”. Then, I iterate through the array of integers passed by the method. If the current index value is less than the next index value, I set “result” to “true”, and repeat the loop. Else, I’ll set “result” to “false”, break out of the loop and set “result” to “false”. After the FOR loop, I return “result”.

However, I’ve been receiving an error message that “result” has not been initialized properly. I can kinda understand the confusing with the JVM, however I thought that setting the value for “result” inside of the IF/ELSE statements would solve that.

Here is a copy of the code that I have done so far:

public boolean scoresIncreasing(int[] scores) {
    boolean result;
    for (int i = 0; i < scores.length; i++) {
        if (i < (i + 1)) {
            result = true;
        }
        else {
            result = false;
            break;
        }
    }
    return result;
}
  • 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-05-15T21:20:41+00:00Added an answer on May 15, 2026 at 9:20 pm

    First of all, i < i+1 will always be true, unless i = Integer.maxValue, in which case you’ll wrap around to Integer.minValue.

    What you want is scores[i] < scores[i+1] , and you’ll need to adjust your loop values to avoid an index out of bounds on the last iteration.

    So, your code fixed:

    public boolean scoresIncreasing(int[] scores) {
        boolean result;
        for (int i = 0; i < scores.length-1; i++) // fix loop end
        {
            if (scores[i] < scores[(i + 1)]) {
                result = true;
            }
            else {
                result = false;
                break;
            }
        } // missing brace
        return result;
    }
    

    Try this as an alternative. It works on the principle that once you get a false, you can get out immediately.

    public boolean scoresIncreasing(int[] scores) {
        boolean result = true; // assume true
        for (int i = 0; i < scores.length-1; i++) // fix loop end
        {
            if (scores[i] > scores[(i + 1)]) return false;
        } // missing brace
        return result;
    }
    

    Of course, you may want to introduce bounds checking at the beginning to ensure that there are at least two values.

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

Sidebar

Ask A Question

Stats

  • Questions 463k
  • Answers 463k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Answered here Creating a custom Document Library in SharePoint May 16, 2026 at 12:54 am
  • Editorial Team
    Editorial Team added an answer jQuery UI has a Slider control that you could use… May 16, 2026 at 12:54 am
  • Editorial Team
    Editorial Team added an answer Overview Why do we need the copy-and-swap idiom? Any class… May 16, 2026 at 12:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.