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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:23:03+00:00 2026-06-04T18:23:03+00:00

I need help because my brain cells cannot find what is wrong with this

  • 0

I need help because my brain cells cannot find what is wrong with this program!
Here’s the code

     import java.util.*;
      public class student{
      public static void main (String []args)

    { 
        Scanner sc=new Scanner(System.in);
        System.out.println("enter number elements");  //asking the user to enter the number of integer items 
        int num=sc.nextInt();
        int []myArray= new int[num];
        int maxValue=myArray[0];
        int minValue=myArray[0];
        int i;
        for( i=0; i<myArray.length;i++)
        {System.out.print("Enter element"+(i+1));  //asking the user to enter the items 
           myArray[i]=sc.nextInt();
        }

        for(i=0; i<myArray.length;i++)
        {System.out.print(myArray[i]);    //displaying the elements 
        }
        System.out.println(" ");
        for( i=myArray.length-1; i>=0;i--)
        {System.out.print(myArray[i]);      //displaying the elements in a backward order
        }
        System.out.println(" ");
        for( i=0; i<myArray.length;i++)
        {if(i%2==1)

           System.out.println(myArray[i]);               //displaying the elements in odd indices

        }

      for( i=0; i<myArray.length-1;i++)
        { if(myArray[i]>maxValue)
            {
                maxValue= myArray[i];           //finding the maximum


            }

        }
        System.out.println(maxValue+" "+(i+1));

        for( i=1; i<myArray.length-1;i++)
        { if( myArray[i]<minValue)
            {minValue= myArray[i];                //finding the minimum

            }
        }
       System.out.println(+minValue+" "+(i+1));



        System.out.println(myArray[0]);                          //displaying first item
        System.out.println( myArray[myArray.length-1]);          //displaying last item




        for( i=0; i<myArray.length;i++)
        {if(i%2==0)

          {  myArray[i]= myArray[i]*-1;                    //multiplying items in even indices by -1

        System.out.print( myArray[i]);}
    }
  }

}

The program does what’s in the comment, yet the minimum value is always zero even if I don’t enter it…I cannot figure out what’s the problem, so I’d appreciate your help!

  • 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-04T18:23:04+00:00Added an answer on June 4, 2026 at 6:23 pm

    You initialize you array. And then default values are given (every int is initialized 0)

       int []myArray= new int[num];
       int minValue=myArray[0];
    

    it will be 0

    so nothing smaller can be found than zero if you type in positive integers

    Solution
    First fill your array with the user input
    THEN do

     int minValue=myArray[0];
    

    Or use Integer.MIN_VALUE.

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

Sidebar

Related Questions

I need help converting this code from C# to Java. public static ulong GetChecksum(byte[]
I need help because I am trying to code a game in Java. I
i need your help badly because i cannot solve this problem on my own.
I am here because I need help solving this problem. So I have this
Below is the simple layout. I need help with this because when I scaling
I need help refactoring this multi-loop thing. Here is what I have: Campaign has_many
I really need help on this because I lost my hopes to correct the
I need help with this question. I'm using the camel-http component as shown here
I need help because I didn't find out a solution for a project where
I really need help on this those function DATEDIFF OR DateAdd , because I

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.