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

  Create algorithm to calculte and print average earnings

Create the algorithm to calculte and print average earnings, lowest earnings, and highest earnings of group of employees. Each input record will contain name and earnings of one employee.

  Create algorithm which takes as inputs matrices

Create the algorithm which takes as inputs, matrices C, D, and vertex indices i and j, and returns minimum-cost path from vertex i to vertex j.

  Question about java hashtables

Prompt the user for a string, and display the corresponding number. For example, if the user types "five", the program would output "5". This must be done using the hashtable as created in the previous step.

  Design algorithm based on bfs that colors a graph

Design an algorithm based on BFS that either colors a graph with 2 colors or determines that two colors are not sufficient.

  Question related to ms excel

Discuss how do I insert a row in multiple tables on different sheets in the same workbook? I have twelve sheets, one for every month, and the sheets are exactly the same.

  Define file type

Define File Type and provide some of the important information to know about it and where do file types come from?

  Creating two arrays of integers

Prepare two arrays of integers, each holding 10-elements of data. Make a third array of integers for a result array. The main program will take the 2-arrays of integers and pass them to the function subtract().

  Write algorithm to calculate the median using queries

Calculate the median using as few queries as possible. Provide an algorithm which determines the median value using at most O(lg n) queries.

  Creating database for charity event

Your Project is to organize a charity event. You must use at least two events, one of which must be a Windows program such as Word, WordPad, or Paint.

  Algorithm for string of numbers recognize all the substrings

Write down algorithm, using pseudocode, to perform the following task, Given a string of numbers, recognize all of the substrings that form numbers that are divisible by 3.

  Binary search tree adt

Write a client method that returns a count of the number of nodes in a binary search tree that contain a value less than or equal to the argument value.

  Creating sql statements

Create three SQL statements: the 1st statement should add pending amounts to appropriate accounts, the second statement should subtract the pending amounts from appropriate accounts,

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