0% found this document useful (0 votes)
2 views

Java Lab 10

The document outlines a Java lab assignment focused on arrays. It instructs students to create a Java file, set up a program with a predefined integer array, and implement functionality to print the array in both normal and reverse order, as well as to generate and print an array of random numbers. Additionally, it provides guidance on accessing and assigning values to array elements.

Uploaded by

arya.santosh2007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java Lab 10

The document outlines a Java lab assignment focused on arrays. It instructs students to create a Java file, set up a program with a predefined integer array, and implement functionality to print the array in both normal and reverse order, as well as to generate and print an array of random numbers. Additionally, it provides guidance on accessing and assigning values to array elements.

Uploaded by

arya.santosh2007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Lab 10 – Arrays

 Create a new Java file (empty Java file), save it to your H: drive, call it lab10
 Insert the following code to set up your program:
 Be sure to copy the test text files to the location where you saved your Java file

import java.util.Scanner;

public class lab10 {

public static void main (String args[]){

Scanner input = new Scanner(System.in);

int[] intArray = {1,2,3,4,5,6,7,8,9,10};

100pt:

Write a program that:

 Loops through and prints out the array intArray. Use either a for loop or a while loop to achieve
this.
 Prints out the array intArray in reverse order. Again, use a for loop or a while loop to achieve
this.
 Create a new array, with a length of 10. Use a loop to fill this array with 10 random numbers
between 0 and 999. Use a loop to print this array out after it has been filled.
Notes:

To access an array element at the zeroth index position:

intArray[0]

To assign a value to a given index position:

intArray[x] = 10;

To create a new array of length 5:

int[] exampleArray = new int[5];

You might also like