answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nataliya [291]
1 year ago
11

Write a program FindDuplicate.java that reads n integer arguments from the command line into an integer array of length n, where

each value is between is 1 and n, and displays true if there are any duplicate values, false otherwise.
Computers and Technology
1 answer:
kozerog [31]1 year ago
7 0

Answer:

  1. public class FindDuplicate{
  2.    public static void main(String[] args) {
  3.        Scanner input = new Scanner(System.in);
  4.        int n = 5;
  5.        int arr[] = new int[n];
  6.        for(int i=0; i < arr.length; i++){
  7.            int inputNum = input.nextInt();
  8.            if(inputNum >=1 && inputNum <=n) {
  9.                arr[i] = inputNum;
  10.            }
  11.        }
  12.        for(int j =0; j < arr.length; j++){
  13.            for(int k = 0; k < arr.length; k++){
  14.                if(j == k){
  15.                    continue;
  16.                }else{
  17.                    if(arr[j] == arr[k]){
  18.                        System.out.println("True");
  19.                        return;
  20.                    }
  21.                }
  22.            }
  23.        }
  24.        System.out.println("False");
  25.    }
  26. }

Explanation:

Firstly, create a Scanner object to get user input (Line 4).

Next, create an array with n-size (Line 7) and then create a for-loop to get user repeatedly enter an integer and assign the input value to the array (Line 9 - 14).

Next, create a double layer for-loop to check the each element in the array against the other elements to see if there is any duplication detected and display "True" (Line 21 - 22). If duplication is found the program will display True and terminate the whole program using return (Line 23). The condition set in Line 18 is to ensure the comparison is not between the same element.

If all the elements in the array are unique the if block (Line 21 - 23) won't run and it will proceed to Line 28 to display message "False".

You might be interested in
Write a class with a constructor that accepts a String object as its argument. The class should have a method that returns the n
mote1985 [20]

Answer:

import java.util.Scanner;

public class VowelsAndConsonantsDemo {

   /**

   The printMenu methods displays a menu to the user

    */

   public static void printMenu() {

       System.out.println("Please select an option: ");

       System.out.println();

       System.out.print("a. Count the number of vowels in the string.\n"

               + "b. Count the number of consonants in the string.\n"

               + "c. Count both the vowels and consonants in the string.\n"

               + "d. Enter another string.\n"

               + "e. Exit the program\n");

   }

   public static void main(String[] args) {

       String input;      // to hold the user's input

       String option;     // to hold the user's input

       char choice;       // to hold a single character

       char exit;         // user chooses 'e' to exit the program

       char letter;       //the Y or N from the user's decision to exit

       // create a Scanner object to read keyboard input.

       //  Scanner keyboard = new Scanner(System.in);

       Scanner keyboard;

       do {

           keyboard = new Scanner(System.in);

           // ask user to enter string

           System.out.print("Enter a string: ");

           input = keyboard.nextLine();

           input = input.toLowerCase();

           System.out.println();

           printMenu();

           option = keyboard.nextLine();

           choice = option.charAt(0);

           VowelsAndConsonants words = new VowelsAndConsonants(input);

           switch (choice) {

               case 'a':

               case 'A':

                   System.out.println("Number of Vowels: " + words.getVowels());

                   break;

               case 'b':

               case 'B':

                   System.out.println("Number of Consonants: " + words.getConsonants());

                   break;

               case 'c':

               case 'C':

                   System.out.println("Number of Vowels & Consonants: " + words.getConsonants()

                           + words.getVowels());

                   break;

               case 'd':

               case 'D':

                   System.out.println("Enter a string: ");

                   break;

               case 'e':

               case 'E':

                   System.exit(0);

                   break;

               default:

                   System.out.println("You did not enter a valid choice.");

           }

           //

           // keyboard.nextLine();    //consumes the new line character after the choice

           // String answer = keyboard.nextLine();

           // letter = answer.charAt(0);

       } while (true);

   }

}

4 0
1 year ago
Which of the following provides a suite of integrated software modules for finance and accounting, human resources, manufacturin
zzz [600]

Answer:

B) ERP systems

Explanation:

ERP which means Enterprise Resource Planning is a software that uses a centralized database, it helps to hasten business processes thereby reducing the use of manual labour. Some of the integrated software modules which it provides are:

*Finance, Accounting.

*Human resource.

*Manufacturing and production.

*Sales and marketing.

The ERP system does not really need the total involvement of a human because it has a database where information stored is used in the daily execution of tasks, it can also be used to measure the productivity and profitability of the business.

6 0
2 years ago
Match the vocabulary word to the accurate definition. A software program that enables you to search for, interact with, and retr
SashulF [63]

Answer:

A software program that enables you to search for, interact with, and retrieve information resources: Search Engine

A method by which data is transferred from one computer to another through the Internet Data Transfer

Coordinates actions between the user interface and the rendering engine: Operating Systems

Handles requests for information resources from networked servers: SERVER

Includes web pages, images, videos, music files, and other forms of content WEBSITE

Enables a browser to save browsing information Advanced Settings  

Includes an address bar, Back and Forward buttons, bookmarking menu, and other useful features Web browser

Displays content on the screen. Monitor

Explanation:

If you enable the browser to remember the browser experience, then you certainly need to go inside the advanced settings and from there you can check remember last 7 days and other options. Content is displayed on Monitor, And it is the website that shows images, video, text etc. The information resources are being controlled through the server, and Data transfer is the transfer of the data from one computer to other via a proper network. And the Data is collected, interacted as well as retrieve information via the search engines. And operating system is definitely the interface, and an educated one in between user interface and the rendering engine.

4 0
1 year ago
Read 2 more answers
Explain what might happen if two stations are accidentally assigned the same hardware address?
Firdavs [7]

Answer: If two different station are addressed with the same hardware address then there are chances of occurrence of the failure in the network at irregular intervals.The failure or error will occur because of the both the devices are seen as one by the network due to same address.

An intelligent network system id used ,it can identify the error can help in the prevention of the failure.Other option for configuring the situation is assigning the MAC(media access control)address to devices which are unique in nature thus, no device can have same address.

5 0
1 year ago
Write a statement to add the key Tesla with value USA to car_makers. Modify the car maker of Fiat to Italy. Sample output for th
marishachu [46]

Answer:

Input code:

car_makers = {'Honda': 'Japan', 'Fiat': 'Germany'}

#add Tesla and USA as corresponding value

car_makers['Tesla'] = 'USA'

#change Fiat entry to Italy instead of Germany

car_makers['Fiat'] = 'Italy'

print(car_makers)

print('Honda made in', car_makers['Honda'])

print('Fiat made in', car_makers['Fiat'])

print('Tesla made in', car_makers['Tesla'])

Explanation:

The first line is a define object in the python code, containing two entries of Honda and Fiat and their respective countries.

The python code adds an entry to the object "car maker" using the bracket notation, the tesla car from USA.

The country of the Fiat car is changed from Germany to Italy, using the bracket notation.

The output of the complete object and the individual cars is given.

<u>output of the python code:</u>

{'Honda': 'Japan', 'Fiat': 'Italy', 'Tesla': 'USA'}

Honda made in Japan

Fiat made in Italy

Tesla made in USA.

7 0
1 year ago
Other questions:
  • _____ is the process of adjusting colors in an image.
    13·2 answers
  • python Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value i
    7·1 answer
  • Mike has never used a slide software before, but he needs to create a presentation by the end of the week. what recourse would b
    8·1 answer
  • If, instead, charge 3 is located to the left of charge 1 at a point (on the x axis) that satisfies the conditions given in the p
    7·1 answer
  • Write an expression that will cause the following code to print "18 or less" if the value of user_age is 18 or less. Write only
    9·2 answers
  • To play game, go inside the Grand Theft Auto V folder and right click and runGTAVLauncher as administrator.If you get any missin
    5·1 answer
  • Krista needs to configure the default paste options in PowerPoint 2016. Which area of the Options dialog box will she need to us
    14·1 answer
  • Return 1 if ptr points to an element within the specified intArray, 0 otherwise.
    7·1 answer
  • In a system where Round Robin is used for CPU scheduling, the following is TRUE when a process cannot finish its computation dur
    13·1 answer
  • The dealer's cost of a car is 85% of the listed price. The dealer would accept any offer that is at least $500 over the dealer's
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!