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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:28:00+00:00 2026-05-31T23:28:00+00:00

I am trying to build a program that accepts an array of integers as

  • 0

I am trying to build a program that accepts an array of integers as parameter and returns a String. The string would be “ascending” if the array is sorted from the smallest to the greatest, “descending” if the array is sorted from the greatest to the smallest, “not sorted” is the array is not sorted at all and “all the same” if all elements of the array are equal.

So far I have the following code below. Am I on the right track? I keep getting an error on the line indicated below saying “The operator > is undefined for the argument type”. Any idea what could cause it?

import java.util.*;
import java.io.*;
import java.util.Scanner;

public class arrayCheck {
    public static void main(String[] args) throws IOException {
        arrayInput();
        isSorted(null);
    }

    public static String arrayInput() {
        int size = 0;
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the size of the array: ");
        size = in.nextInt();
        System.out.println("The size you enetered is " + size);
        int[] array = new int[size];
        System.out.println("Enter the array: ");
        int j = 0;
        while (j < size) {
            System.out.print("Enter int"+ (j + 1) + ": ");
            array[j] = in.nextInt();
            ++j;
        }
        in.close();
        String arrayS = Arrays.toString(array);
        return arrayS;
    }

    public static String isSorted(String[] arrayS) {
        int n = arrayS.length;
        for (int i = 0; i < n - 1; ++i)
            if (arrayS[i] > arrayS[i + 1])   //ERROR ON THIS LINE
                return "not ascending";
        return "ascending";
    }
}
  • 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-31T23:28:02+00:00Added an answer on May 31, 2026 at 11:28 pm

    The error means that the operator > is not defined for the String type, which is the element type of your arrays. The operators < and > are only usable on primitive types like int or long, not on objects.

    Here you need to use String.compareTo instead, like this:

        if (arrayS[i].compareTo(arrayS[i+1]) > 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a small program that hosts vst effects and I would
Helllo! I'm trying to build a program that calculates the best score from a
I am trying to build a server program that receives file from client using
So, i'm trying to build a program that takes 2 integers. Later it splits
I'm trying build a method which returns the shortest path from one node to
I am trying to build a program that will get all the system keyEvents
I was trying to build a program that puts a radical into simplest radical
I am trying to build a program that uses libusb and I get a
I am trying to build a program that, once the button was click, every
I'm trying to build a program that goes like this: User enters 3 numbers.

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.