Processing Arrays Using Loops: A Java Programming Lab Report, Study Guides, Projects, Research of C programming

Object-oriented programming (OOP) refers to a type of computer programming (software design) in which programmers define the data type of a data structure, and also the types of operations (functions) that can be applied to the data structure.

Typology: Study Guides, Projects, Research

2019/2020

Uploaded on 01/11/2020

samia-khan-2
samia-khan-2 🇵🇸

4.8

(4)

11 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
LAB REPORT: #6
SUBJECT Basic arrays
SUBMITTED BY: SAMIA
REG. NO: 17JZBCS0022
DEPARTMENT: CS&IT
TITLE: Processing arrays using loops
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Processing Arrays Using Loops: A Java Programming Lab Report and more Study Guides, Projects, Research C programming in PDF only on Docsity!

LAB REPORT:

SUBJECT Basic arrays

SUBMITTED BY: SAMIA

REG. NO: 17JZBCS

DEPARTMENT: CS&IT

TITLE: Processing arrays using loops

Exercise 1:

- In BlueJ, create a new project called Lab - Create a class in that project called MyArrays - Write a method in that class called arrayPlay that takes no parameters and returns no value - In arrayPlay, create an array called myNums that can hold 20 integers. - What are the valid indexes for this array? SOLUTION: Figure I

Exercise 2:

- Create a Random object for generating random numbers. Remember to import the java.util.Random class. - Use a for loop to fill the myNums array with random integers in the range 100 to 200. - Make sure the program compiles, though running it at this point still won't produce any output. - Could you have filled the array with a for-each loop instead?

SOLUTION:

Figure 4

Exercise 4:

- Print a blank line to separate the initial values from the following output. - Use a regular for loop to print every third value in the array starting with the first one. - That is, print the first value, the fourth value, the seventh value, etc.

- Once again: could a for-each loop be used for this? SOLUTION: Figure 5

Exercise 5:

- Print another blank line. - Now print the values in the array backwards, starting with the last position and moving to the first. - Regular for loop or for-each loop?

SOLUTION:

Figure IV Figure V

Exercise 7:

- Print another blank line. - Now print the index AND the value for each value that's over 170 - For example: 4 184 12 172 14 190 18 179 - Run your program several times. Results will vary.

SOLUTION:

Figure VI Figure VII

Exercise 8:

- Now write separate method called countValues that accepts an integer array as a parameter. Call the parameter list. - The method should return the number of values in the array that are less than 150. - In the arrayPlay method, call the countValues method, passing in the myNums array, and print the result: The number of values less than 150 are xxx