Professional Documents
Culture Documents
-------------------------------
public class test {
System.out.println(output);
}
Output:abc
To Print no of occurences of each character in String in Java:
--------------------------------------------------------------
public class occurenceOfCharacter {
public static void main(String[] args) {
String str = "SSDRRRTTYYTYTR";
HashMap <Character, Integer> hMap = new HashMap<>();
for (int i = str.length() - 1; i > = 0; i--) {
if (hMap.containsKey(str.charAt(i))) {
int count = hMap.get(str.charAt(i));
hMap.put(str.charAt(i), ++count);
} else {
hMap.put(str.charAt(i),1);
}
}
System.out.println(hMap);
}
}
output:
-------
{D=1, T=4, S=2, R=4, Y=3}
public class SmallestNumberInAnArray {
public static void main(String args[]){
int temp, size;
int array[] = {10, 20, 25, 63, 96, 57};
size = array.length;