0% found this document useful (0 votes)
41 views2 pages

1st Mini Project

The document contains code snippets for three different problems: counting the frequency of characters in a string, counting the digits in a number, and looking up a value in a hash map based on a key.

Uploaded by

vosew12190
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views2 pages

1st Mini Project

The document contains code snippets for three different problems: counting the frequency of characters in a string, counting the digits in a number, and looking up a value in a hash map based on a key.

Uploaded by

vosew12190
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1:=======================================================

char[] array = str.toCharArray();

int count = 0;
for(int i=0;i<array.length;i++)
{
if(ch == array[i])
{
count = 1;
for(int j=i+1;j<array.length;j++)
{
if(ch == array[j])
{
count += 1;
array[j] = '0';
}

}
}
else
continue;
}

return count;

2:===============================================================

public class Solution {


public static void main(String args[] ) throws Exception {
Scanner sc= new Scanner(System.in);
int number = sc.nextInt();

for(int i = 0; i <= 9; i++){


int count = 0;
for(int j = number; j != 0; j /= 10){
int digit = j % 10;
if(i == digit)
count++;
}
if(count > 0){
System.out.println(i + ": " + count);
count = 0;
}
}
}

3:=========================================================

public class Solution {


public static void main(String args[] ) throws Exception {

HashMap<Integer, String> hashMap = new HashMap<>();


Scanner input = new Scanner(System.in);
int number = Integer.parseInt(input.nextLine());
for(int i=0;i<number;i++)
{
int key = input.nextInt();
String value = input.nextLine();
hashMap.put(key,value.trim());

}
int userKey = input.nextInt();

boolean result= hashMap.containsKey(userKey);


if(result)
{
System.out.println(hashMap.get(userKey));
}
else
{
System.out.println("-1");
}
}
}

You might also like