This is the 14th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

🌲 this article is included in the column “Java introduction exercise 100 cases” – try to learn the “Java basic grammar” after the consolidation and improvement and “LeetCode brush” before the small test knife.

Like it and see. Make it a habit. Wechat search [a coding] follow this programmer who is struggling in the Internet.

This article is included in the technical expert training, which contains my learning route, series of articles, interview question bank, self-study materials, e-books, etc. Welcome to star ⭐ ️

Topic describes

Difficulty: Easy

Outputs the element with the smallest value and its index in a one-dimensional array of integers.

knowledge

  • A one-dimensional array
  • The sorting

Their thinking

1. What is array

An array is a collection of variables of related types that can operate in a uniform way.

Define an array

int data[] = new int[3];
// The length of the array is 3, and the index exceeds the bounds, and the index starts at 0
Copy the code

Add elements

data[0] = 10; // The first element
data[1] = 20; // The second element
data[2] = 30; // The third element
Copy the code

Loop to print

for(int x = 0; x < data.length; x++) {
			System.out.println(data[x]); // Control indexes through loops
}
Copy the code

2. Sorting algorithm

Actually, we don’t use sorting algorithms strictly, but there are some ideas in there, and if you want to get a sense of them, you can read this.

Bubble sort

Code implementation

/** * Outputs the element in the one-dimensional array with the smallest value and its index. * /
public class question_09 {
    public static void main(String args[]) {
        int a[] = { 12.24.6.37.3.22.64 };
        int min = 0;
        for (int i = 1; i < a.length; i++) {
            if (a[min] > a[i]) {
                min = i;
            }
        }
        System.out.println("a[" + min + "] ="+ a[min]); }}Copy the code

The output

Expand the summary

This section exercises with one-dimensional arrays, and the next section exercises with two-dimensional arrays.

The last

One foot is difficult to go, one hand is difficult to sing, a person’s power is limited after all, a person’s journey is doomed to be lonely. When you set a good plan, with full of blood ready to set out, must find a partner, and Tang’s monk to the West, the master and his disciples four people united as one to pass the ninety-eight difficult. So,

If you want to learn Java well

Want to go to company

Want to get high salary

Want to have a group of like-minded partners

Please join the technical exchange