java getDup accepts an array and returns an int. If there is any element is duplicated, the method counts how many of those present in the array. Example :   getDup(["1","2","aa"',"1"])   returns:2 ("1" is duplicated and there are two "1"s so return is 2)   class Main {      public static int getDup(String[] r) {              }   public static void main(String[] args) {       Scanner in = new Scanner(System.in);       String [] strs = new String[in.nextInt()];       for(int i=0; i < strs.length; i++) {         strs[i] = in.next();       }     System.out.println(getDup(strs));   }  } hint: you will need a nested array the will run on the array we get from the method argument. inside the nested loop you will need to check if the main array element is equal to the current

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter6: Using Arrays
Section: Chapter Questions
Problem 19RQ
icon
Related questions
Question

java

getDup accepts an array and returns an int.

If there is any element is duplicated, the method counts how many of those present in the array.

Example :

 
getDup(["1","2","aa"',"1"])
 
returns:2
("1" is duplicated and there are two "1"s so return is 2)
 

class Main {
  
  public static int getDup(String[] r) {
    
   

 

  }

  public static void main(String[] args) {
      Scanner in = new Scanner(System.in);
      String [] strs = new String[in.nextInt()];
      for(int i=0; i < strs.length; i++) {
        strs[i] = in.next();
      }

    System.out.println(getDup(strs));

  } 

}

hint:

  • you will need a nested array the will run on the array we get from the method argument.
  • inside the nested loop you will need to check if the main array element is equal to the current
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT