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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:14:33+00:00 2026-05-28T13:14:33+00:00

I am learning Java, now working with arrays. I am doing an excercise where

  • 0

I am learning Java, now working with arrays. I am doing an excercise where I am going to make the user input the values for a two-by-three integer array. Then I am supposed to find the smallest value. I do this by using an if-statement. The problem is that the compiler always prints the number “0” for the smallest value. I cannot find out what´s wrong with my code. Can anyone please help me?
The code is as follows:

  import java.util.Scanner;
  public class Oppgave79k 
  {
public static void main(String[] args) 
{
    Scanner input = new Scanner(System.in);
    int t[][] = new int[2][3];
    int smallest = t[0][0];

    for (int row = 0; row < t.length; row++)
        {
        for (int column = 0; column < t[row].length; column++)
            {
            System.out.println("Enter values for array: ");
            t[row][column] = input.nextInt();
            if (t[row][column] < smallest)
                {
                smallest = t[row][column];
                }
            }
        }
    for (int row = 0; row < t.length; row++)
        {
        for (int column = 0; column < t[row].length; column++)
            {
            System.out.printf("%d ", t[row][column]);
            }
        }
    System.out.printf("Smallest element is: %d\n", smallest);
}

}

  • 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-28T13:14:34+00:00Added an answer on May 28, 2026 at 1:14 pm

    In these lines:

    int t[][] = new int[2][3];
    int smallest = t[0][0];
    

    you’ve started off with smallest as 0. So unless you enter a negative number, it’s never going to change.

    You could use:

    int t[][] = new int[2][3];
    int smallest = Integer.MAX_VALUE;
    

    to make sure that the first number entered is used.

    As an aside, your indentation style is somewhat unconventional. Either

    for (...) {
        // Code
    }
    

    or

    for (...)
    {
        // Code
    }
    

    look fine to me, but

    for (...)
        {
        // Code
        }
    

    is very unusual.

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

Sidebar

Related Questions

I'm learning Java, and now that I'm over the packages hump, things are going
I'm learning how to develop SOAP web services with Java. So far now I've
I've been doing quite large application recently with Java - Swing. Now I'd like
I am new to programming. I am learning Java now, there is something I
I'm learning Java right now but I'm wondering if there is a hierarchy of
Which one should I install when I want to start learning Java? I'm going
Due to my future course in Computer Science, I'm now going to start learning
I am learning java and started with classes and I am now having some
Well..I am learning java now and I am curious to know will this yield
I am learning java ee right now. I have successfully implemented a hello-world style

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.