1 answer

Ll this is a java code do it in eclipse please. thank you. Lab Objectives This...

Question:

Lab Objectives This lab was designed to reinforce programming concepts from this lab, you will practice: • Declaring and initll

this is a java code do it in eclipse please. thank you.

Lab Objectives This lab was designed to reinforce programming concepts from this lab, you will practice: • Declaring and initializing arrays. • Comparing input to array elements. • Preventing array out-of-bounds errors. The follow-up questions and activities will also give you practice: • Initializing array sizes during program execution. • Generalizing programs. Description Use a one-dimensional array to solve the following problem: Write an application that inputs five numbers, each of which is between 10 and 100, inclusive. As each number is read, display it only if it is not a duplicate of a number already read. Provide for the “worst case,” in which all five numbers are different. Use the smallest possible array to solve this problem. Display the complete set of unique values input after the user inputs each new value. Sample Output Enter number: 11 11 Enter number: 85 11 85 Enter number: 26 11 85 26 Enter number: 11 11 has already been entered 11 85 26 Enter number: 41 11 85 26 41

Answers

Answer:

import java.io.*;
import java.util.*;
public class Main
{
   public static void main(String[] args) {
       int num[]=new int[5]; //array num of size 5
       int temp=0,count,k=0;
       Scanner s=new Scanner(System.in);
       for(int i=0;i<5;i++) //this loop will make sure to enter 5 numbers each of which is b/w 10 and 100
       {
       count=0; //this is to increment if duplicate is found
       System.out.print("Enter number:");
       temp=s.nextInt();
       while(temp<10 || temp>100){ //this loop will take care to enter element b/w 10 and 100
       System.out.println("number should be b/w 10 and 100");
       System.out.print("Enter number:");
       temp=s.nextInt();
       }
       for(int j=0;j<k;j++) //comparing input to elements in array
       {
       if(temp==num[j])
       {
       count++;
       System.out.print(temp+" has already been entered ");
       }
       }
       if(count==0)
       {
       num[k]=temp; //input is stored into array only if no duplicate is foundd
       k++; //k is used for indicating number of values stored in to array
       }
       for(int l=0;l<k;l++)
       {
       System.out.print(num[l]+" "); //this is for printing elements
       }
       System.out.println();
       }
   }
}

OUTPUT:

Enter number:11 Enter number:85 11 85 Enter number:26 11 85 26 Enter number:11 11 has already been entered 11 85 26 Enter num

Enter number:10 10 Enter number: 100 10 100 Enter number:9 number should be b/w 10 and 100 Enter number:11 10 100 11 Enter nu

you could see here it increments value of k only if it is between 10 and 100 such that values entered less than 10 and greater than 100 are invalid.

.

Similar Solved Questions

1 answer
Question 13 (2 points) If two events are mutually exclusive, then their probabilities can be added...
Question 13 (2 points) If two events are mutually exclusive, then their probabilities can be added all of the choices are correct they may also be collectively exhaustive if one occurs, the other cannot occur the joint probability is equal to O Question 14 (1 point) The area under the normal distrib...
1 answer
The hand moves the end of the Slinky up and down through two complete cycles in...
The hand moves the end of the Slinky up and down through two complete cycles in one second. The wave moves along the Slinky at a speed of 0.386 m/s. Find the distance between two adjacent crests on the wave....
1 answer
Write a C++ program and algorithm to create a class of fraction having variables numerator and...
Write a C++ program and algorithm to create a class of fraction having variables numerator and denominator, and member functions setting and getting values of the fractions. Also create a static member variable of the class having fraction value tolerance of 0.1. Instantiate 10 fraction objects and ...
1 answer
11: Three charges are fixed at the corners of a rectangle as shown. Find the magnitude...
11: Three charges are fixed at the corners of a rectangle as shown. Find the magnitude and direction of the electric field at the 4h corner. la m JAC 5m 12: Draw electric field lines for the following situations: A: A single charge -2Q. B: Two charges:+Q and +3Q C: Two charges: Q, the other of -2Q...
1 answer
A 27-year-old female presents for clinical evaluation at the chiropractic office with a C/C of a...
A 27-year-old female presents for clinical evaluation at the chiropractic office with a C/C of a 4-week-history of recurrent, short episodes of vertigo also reveals various associated symptoms for the past year, including transient U/L limb weakness, transient upper extremity paresthesia and numbnes...
1 answer
Question 1 of 3 View Policies Current Attempt in Progress The following trial balance of Blossom...
Question 1 of 3 View Policies Current Attempt in Progress The following trial balance of Blossom Ltd., at the end of its first year of operations, June 30, 2021, does not balance: Debit Credit $1,241 $2,610 860 3.200 600 2.865 1,200 Cash Accounts receivable Supplies Equipment Accumulated depreciatio...
1 answer
Can we predict when Solar System objects will occult a star?
Can we predict when Solar System objects will occult a star?...
1 answer
1. A sample of solid chromium is heated with an electrical coil. If 85.0 Joules of energy are added to a 11.3 gram sampl...
1. A sample of solid chromium is heated with an electrical coil. If 85.0 Joules of energy are added to a 11.3 gram sample and the final temperature is 39.2 °C, what is the initial temperature of the chromium? 2. She heats 18.6 grams of copper to 97.81 °C and then drops it into an insulated...
1 answer
5) Let F(t) te), te,t >for t e R. Find (t)dt. 0 te, tet, tdt 0
5) Let F(t) te), te,t >for t e R. Find (t)dt. 0 te, tet, tdt 0...
1 answer
6. The perimeter of a rectangle is 60 centimeters. The length of the rectangle is 17...
6. The perimeter of a rectangle is 60 centimeters. The length of the rectangle is 17 centimeters. How wide is the rectangle? 17 cm [A] 43 cm [B] 14 cm [C] 17 cm [D] 13 cm...
1 answer
HP Parameters 1. Initial Cost ($) 2. Revenues ($) Apple Dell 15,000 22,000 45,000 at EOY1...
HP Parameters 1. Initial Cost ($) 2. Revenues ($) Apple Dell 15,000 22,000 45,000 at EOY1 | 43,000 at EOY1 increasing by increasing by $5,000 2.0% annually annually thereafter thereafter 41,000 at EOY1 | 38,000 at EOY1 increasing by decreasing by 1% annually 2% annually thereafter thereafter 26,000 ...
1 answer
Here is a bivariate data set. х 94 94 81 67 у 98 -7 21 69...
Here is a bivariate data set. х 94 94 81 67 у 98 -7 21 69 85 84 70 46 68 55 89 22 -65 10 -31 215 Find the correlation coefficient and report it accurate to four decimal places. r= Check Answer...
1 answer
What is Plagiarism? a) Copying images/content directly from other sources and pasting it b) Pasting other...
What is Plagiarism? a) Copying images/content directly from other sources and pasting it b) Pasting other website links in the solution c) Copying the content directly from text book/ reference books d) All the above...
1 answer
Case Presentation Miguel is a 63 year male patient who presented to the emergency department complaining...
Case Presentation Miguel is a 63 year male patient who presented to the emergency department complaining of a week history of progressive dyspnea, wheezing and productive cough with whitish phlegm. He denies any recent cold or flu-like symptoms. Miguel also denies any fever or chills. He has been us...
1 answer
Discuss with an acquaintance the use of the term survivor rather than victim. Can you identify...
Discuss with an acquaintance the use of the term survivor rather than victim. Can you identify circumstances where one term is preferred over the other? Consider your actions/response if you believe there has been abuse of a client, but your provider/employer says, “Leave it alone. Don’t...
1 answer
Assume that a sample is used to estimate a population mean μμ. Find the margin of...
Assume that a sample is used to estimate a population mean μμ. Find the margin of error M.E. that corresponds to a sample of size 22 with a mean of 21.3 and a standard deviation of 19.4 at a confidence level of 99.5%. Report ME accurate to one decimal place because the sample statistics are p...