Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Data Structure Expert

Arrays & more loops practice

Project name:A170_E15_YourLastName_YourFirstName

Submit: Zip the folder and drop it in the Q drive.

PART A. Write a program ArraysAndLoops and implement the following in the main method:

1. Declare an array arr1 and initialize it to 1, 2, 3, 4, 5, 6, 7, 8, and 9

(For the rest of PART A, use the instance variable length instead of a number to define the capacity of

the array.)

2. Declare another array arr2, the same length as arr1, without giving it any initial values.

3. Using a for loop print arr1 displaying all elements on one line, separated by a comma (commas must

be placed only between numbers).

4. Using a while loop, print arr2 displaying all elements on one line, separated by a dash (dashes must be

placed only between numbers).

5. Using a for loop, copy all the values of arr1 into arr2 in reverse order.

6. Using a do/while loop, print arr1 displaying all elements on one line, separated by a comma.

7. Using a for loop, print arr2 displaying all elements on one line, separated by a dash.

Expected Output

Array 1: 1,2,3,4,5,6,7,8,9

Array 2: 0-0-0-0-0-0-0-0-0

Array 1: 1,2,3,4,5,6,7,8,9

Array 2: 9-8-7-6-5-4-3-2-1

PART B. Write a program, Passwords, that contains an array of five names and another array of five passwords

(your choice). Your program should ask the user to enter a name and a password. If the user enters the correct

name with its related password, grant access (e.g. display â??Access granted!â??). If the user enters the wrong

name/password (can be either or both), allow the user to re?try only once. If the user still cannot enter the

correct name/password, display the following: â??Sorry, your username/password does not match our database.

Contact the administrator.â??

 

PART C. Write a program, ArrayRange, that asks the user to input integers and that displays the difference

between the largest and the smallest. You should ask the user the number of integers s/he would like to enter

(this will allow you to set the length of the array). Allow the user to input all the numbers and then store them

in the array. Search the array for the largest number, then search for the smallest, and finally compute the

calculation. Display all the numbers given by the user, the max number, the min number, and the difference.

THIS IS MY PART C: I WAS WONDERING IF YOU COULD FIX IT I CANNOT FIND THE ERROR

 

import java.util.Scanner;

 

 

public class ArrayRange

{

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

 

int[] array = new int[10];

int inputInteger = 0;

 

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

{

inputInteger = input.nextInt();

array[i] = inputInteger;

}

 

int maxNumber = array[0];

int minNumber = array[0];

 

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

{

if ( array[i] > maxNumber)

maxNumber = array[i];

}

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

{

if ( array[i] < minNumber)

minNumber = array[i];

}

 

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

System.out.print(array[i] + " ");

 

System.out.println();

System.out.println("max number in this array is " + maxNumber);

System.out.println("min number in this array is " + minNumber);

 

int difference = maxNumber - minNumber;

System.out.println("difference between the largest and the smallest is " + difference);

}

}

 

 

Data Structure, Computer Science

  • Category:- Data Structure
  • Reference No.:- M9455633

Have any Question?


Related Questions in Data Structure

Data Communication Delivering Information anywhere

Topic: Data Communication Delivering Information anywhere. Write a 9-12 pages paper in which you: Present an overview of the origin and history of the concept. Describe the current use of and attitude toward the concept. ...

Problem regarding the management program

Problem: Looks like its just adding a save and load feature to the same file you sent me for python 3.5 Until now, you have had to leave your team management program running on your computer indefinitely since you did no ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As