Sollicitatievraag

Sollicitatiegesprek voor de functie Applications Developer

-

Zoho

Write a Java program to count the number of occurances of each number in a series of numbers.

Antwoord

Antwoorden op sollicitatievragen

5 antwoorden

3

public static void main(String[] args) { int occurrence = 0; Map m = new HashMap(); List nos = new LinkedList(); nos.add(1); nos.add(1); nos.add(2); nos.add(3); nos.add(4); nos.add(3); nos.add(2); nos.add(4); nos.add(5); nos.add(100); Set uniqueNos = new HashSet(nos); for(int temp:uniqueNos) { for(int tempList:nos) { if(temp == tempList) { occurrence++; } } m.put(temp, "Appears "+occurrence +" times"); occurrence = 0; } System.out.println(m); }

Devanand op

0

public class FirstJava { public static void main(String[] args) { int occurrence = 0; List nos = new LinkedList(); nos.add(1); nos.add(1); nos.add(2); nos.add(3); nos.add(4); nos.add(3); nos.add(2); nos.add(4); nos.add(5); nos.add(100); Map uniqueNumberCount = new HashMap(); for(int datano:nos){ int k=1; if(uniqueNumberCount.containsKey(datano)){ k=uniqueNumberCount.get(datano); } uniqueNumberCount.put(datano, k); } for(Map.Entry unique:uniqueNumberCount.entrySet()){ System.out.println(unique.getKey()+" Unique Value --->"+unique.getValue()); } } }

Anoniem op

0

import java.util.Scanner; public class Occurrence { public static void main(String[] args) { int n, count = 0, i = 0; Scanner s = new Scanner(System.in); System.out.print("Enter no. of elements you want in array:"); n = s.nextInt(); int a[] = new int[n]; int x[] = new int[n]; System.out.println("Enter all the elements:"); for(i = 0; i < n; i++) { a[i] = s.nextInt(); } System.out.print("Enter the element of which you want to count number of occurrences:"); for(i = 0; i < n; i++) { x[i] = a[i]; } for(i = 0; i < n; i++){ count = 0; for(int j = 0; j < n; j++) { if(a[j] == x[i]) { count++; } } System.out.println("Number of Occurrence of the Element:"+a[i]+"is"+count); } } }

Java program to count the number of occurences op

0

import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Test { public static void main(String[] args){ Map map = new HashMap(); Scanner s1 = new Scanner(System.in); int a[] = new int[10]; System.out.println("Please enter the 10 numbers"); for(int i=0;i<10;i++){ a[i]=s1.nextInt(); } for(int j=0;j<10;j++){ int count = 1; for(int k=0;k<10;k++){ if(j!=k){ if(a[j]==a[k]){ count++; } } } map.put(a[j],count); } for(Map.Entry m:map.entrySet()){ System.out.println("The value "+m.getKey()+" occurs "+m.getValue()+" times in the series which u have entered."); } } }

Suhail Rasith R op

0

public class FirstJava { public static void main(String[] args) { int occurrence = 0; List nos = new LinkedList(); nos.add(1); nos.add(1); nos.add(2); nos.add(3); nos.add(4); nos.add(3); nos.add(2); nos.add(4); nos.add(5); nos.add(100); Map uniqueNumberCount = new HashMap(); for(int datano:nos){ int k=1; if(uniqueNumberCount.containsKey(datano)){ k=uniqueNumberCount.get(datano); } uniqueNumberCount.put(datano, ++k); } for(Map.Entry unique:uniqueNumberCount.entrySet()){ System.out.println(unique.getKey()+" Unique Value --->"+unique.getValue()); } } }

Anoniem op

Voeg antwoorden of opmerkingen toe

Meld u aan of registreer u om hier een opmerking over te maken.