Arrays & more loops practice

Assignment Help Data Structure & Algorithms
Reference no: EM13165515

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);

}

}

 

 

Reference no: EM13165515

Questions Cloud

Joint individual tax return : You are to Prepare the Wardens-2019 2012 Form 1040 Joint Individual Tax Return, including Schedules A, B,, C, D, E, and F and Forms 2106, and any other form which you think is appropriate.
Calculate the density of sulfur hexafluoride gas : Chlorine is widely used to purify municipal water supplies and to treat swimming pool waters. Suppose that the volume of a particular sample of Cl2 gas is 8.60 L at 899 torr and 28°C.
Use the henderson-hasselbach equation : Use the Henderson-Hasselbach equation to calculate the pH of an acetate buffer in which the acetate concentration [CH3COO-] is three times greater than the acetic acid [CH3COOH] with a pKa of 4.76.
State what happen to the carbon level of the carbonyl carbon : What happens to the carbon level of the carbonyl carbon when a Grignard reacts with acetone? What happens to the carbon level
Arrays & more loops practice : Write a program ArraysAndLoops and implement the following in the main method:
State what kind of compound is dihydroxypentane : What kind of compound is 2,3-dihydroxypentane? From what precursor do you synthesize the kind of compound that 2,3-dihydroxypentane is?
The main program should create an ifstream : For decryption, the main program should create an ifstream for the file to be decrypted. It should use the getline method of the ifstream to read lines from the file, call the encryption / decryption function with the line to be decrypted, and dis..
People must be in a group in order to guarantee : How many people must be in a group in order to guarantee that two people in the group have the same birthday (don't forget leap year)?
This function should accept a two-dimensional : getLowestInRow. This function should accept a two-dimensional array as its argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The function should return the lowest value in the specif..

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd