Question

Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs...

Java Programming

Use a one-dimensional array to solve the following program. Write an application that inputs six numbers [Keep the numbers in an array]. The numbers must be between 20 and 200, inclusive. If the number is not between 20 and 200, ask for another input. When a number is entered, display the number only if it is not a duplicate of a number already entered. If it is a duplicate of a number already entered, display a message that the number is a duplicate number and ask for another input. Provide for the worst case in which all six numbers are different. Display the complete set of unique values input after the user enters each new value. UPLOAD Duplicate.java

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class Duplicate {
   public static void main(String[] args) {
       int counter[]=new int[201];
       int arr[]=new int[6];
       int n,count=0;
       Scanner sc = new Scanner(System.in);
       while(true) {
           System.out.println("Enter number between (20-200): ");
           n=sc.nextInt();
           if(n<20 || n>200) {
               System.out.println("Number must be between 20-200. Try again");
               continue;
           }
           if(counter[n]==0) {
               counter[n]=1;
               arr[count++]=n;
           }
           else {
               System.out.println("Value already exist. Try again");
               continue;
           }
           printArray(arr,count);
           if(count==6)
               break;
       }
   }

   private static void printArray(int[] arr, int n) {
       for(int i=0;i<n;i++)
           System.out.print(arr[i]+" ");
       System.out.println();
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Java Programming Use a one-dimensional array to solve the following program. Write an application that inputs...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ program; i need 7.14 as well please. 7.13 (Duplicate Elimination with arrayUse a one-dimensional array...

    C++ program; i need 7.14 as well please. 7.13 (Duplicate Elimination with arrayUse a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, validate it and store it in the array only if it isn't a duplicate of a number already read. After reading all the values, display only the unique values that the user entered. Provide for the "worst case" in which all...

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

    ll 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...

  • Write a console application in c# that uses a one dimensional array; prompt the user to...

    Write a console application in c# that uses a one dimensional array; prompt the user to enter letters, ( a, b, c, … z). As each letter is input, store it in the array only if it is not a duplicate of previous letters entered. After 7 unique letters have been entered, display the unique values in the array. Be sure to test with duplicate values.

  • Please help with this C++ problem using Array Use a one-dimensional array to solve the following...

    Please help with this C++ problem using Array Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100. As each number is read validate it and store it in the array. After reading all the values, display only the unique values that the user entered. Make sure you account for the worst case scenario in which all 20 numbers are different. Use the smallest possible array to solve this...

  • Write a java application that is including a three-question multiple choice quiz about Java programming language....

    Write a java application that is including a three-question multiple choice quiz about Java programming language. Each question must have four possible answers (numbered 1 to 4). Also, ask user to type 0 to exit the test. [Assume that a user enters only integers 1,2,3,4, or 0]. Firstly, display a message that this quiz includes three questions about the Java programming language and display that each question has four possible answers. If the answer is correct for the given question,...

  • Java Programming Write a program that will help a student learn multiplication. Use SecureRandom object to...

    Java Programming Write a program that will help a student learn multiplication. Use SecureRandom object to produce two positive integers between 1 and 20. The program should then prompt the user with a question (use a sentinel-controlled loop), such as: How much is 10 times 11? The student then inputs the answer. If the answer is correct display the message “very good” and ask another question. If the answer is wrong to display the message “no, please try again” and...

  • Using Java Create an application that creates and displays a list of names using an array....

    Using Java Create an application that creates and displays a list of names using an array. Then modify the application to create and use a list of numbers. Console for the names application Please enter a name or type “exit” to quit: Diane Please enter a name or type “exit” to quit: Joe Please enter a name or type “exit” to quit: Greta Please enter a name or type “exit” to quit: Henry Please enter a name or type “exit”...

  • Please complete this code for java Lab Write a program as follows: Create an array with...

    Please complete this code for java Lab Write a program as follows: Create an array with 10 elements. The array should contain numbers generated randomly between 1 and 100 Ask the user to enter any number - Search the array to see if the user entered number is in the array If the user-entered number is in the array, print a 'match found' message. Also print at which index the match was found, else print a 'match not found' message...

  • JAVA: (15 marks) Write a program that creates an integer array with 50 random values, prompts...

    JAVA: (15 marks) Write a program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. "Out of Bounds") and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle...

  • Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a...

    Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT