165k views
2 votes
Write a program to assign distinct number between 1 and 200 into an int array of 100 elements in ascending order (you may reuse the code from practice

User Mjuice
by
5.7k points

1 Answer

6 votes

Answer:

import java.util.Arrays;

public class num2 {

public static void main(String[] args) {

int []intArray = new int[100];

for(int i=0; i<intArray.length; i++){

intArray[i] = i+1;

}

System.out.println(Arrays.toString(intArray));

}

}

Step-by-step explanation:

Firstly create an array of size 100 with this statement

int []intArray = new int[100];

Using a for loop add elements into the array starting at i=0+1 (to acheive an asceending order) since i will run from 0-99.

see the attached code and output

Write a program to assign distinct number between 1 and 200 into an int array of 100 elements-example-1
User Caspian Ahlberg
by
5.5k points