write a program in java to input a string and check that how many times a alphabet is repeated
Answers
Answered by
2
hey there steve
import java.util.*; public class Genric<E> { public static void main(String[] args) { Map<String, Integer> unique = new LinkedHashMap<String, Integer>(); for (String string : "House, House, House, Dog, Dog, Dog, Dog".split(", ")) { if(unique.get(string) == null) unique.put(string, 1); else unique.put(string, unique.get(string) + 1); } String uniqueString = join(unique.keySet(), ", "); List<Integer> value = new ArrayList<Integer>(unique.values()); System.out.println("Output = " + uniqueString); System.out.println("Values = " + value); } public static String join(Collection<String> s, String delimiter) { StringBuffer buffer = new StringBuffer(); Iterator<String> iter = s.iterator(); while (iter.hasNext()) { buffer.append(iter.next()); if (iter.hasNext()) { buffer.append(delimiter); } } return buffer.toString(); } }
import java.util.*; public class Genric<E> { public static void main(String[] args) { Map<String, Integer> unique = new LinkedHashMap<String, Integer>(); for (String string : "House, House, House, Dog, Dog, Dog, Dog".split(", ")) { if(unique.get(string) == null) unique.put(string, 1); else unique.put(string, unique.get(string) + 1); } String uniqueString = join(unique.keySet(), ", "); List<Integer> value = new ArrayList<Integer>(unique.values()); System.out.println("Output = " + uniqueString); System.out.println("Values = " + value); } public static String join(Collection<String> s, String delimiter) { StringBuffer buffer = new StringBuffer(); Iterator<String> iter = s.iterator(); while (iter.hasNext()) { buffer.append(iter.next()); if (iter.hasNext()) { buffer.append(delimiter); } } return buffer.toString(); } }
Answered by
2
This is one of the difficult questions in Java. Because It is easy to write in C.
import java.util.Scanner;
class Brainly
{
public static void main(String args[])
{
int num = 0;
System.out.println("Enter a String");
Scanner demo = new Scanner(System.in);
String hell = demo.nextLine().toLowerCase();
for(char i = 'a';i<='z';i++)
{
for(int j=0;j<hell.length();j++)
{
if(hell.charAt(j)==i)
{
num++;
}
}
if(num!=0)
{
System.out.println(i+"="+num);
num=0;
}
}
}
}
Output:
Enter a string: steeve.
s = 1
t = 1
e = 3
v = 1.
Hope this helps! -------------------------------- Gud Luck
import java.util.Scanner;
class Brainly
{
public static void main(String args[])
{
int num = 0;
System.out.println("Enter a String");
Scanner demo = new Scanner(System.in);
String hell = demo.nextLine().toLowerCase();
for(char i = 'a';i<='z';i++)
{
for(int j=0;j<hell.length();j++)
{
if(hell.charAt(j)==i)
{
num++;
}
}
if(num!=0)
{
System.out.println(i+"="+num);
num=0;
}
}
}
}
Output:
Enter a string: steeve.
s = 1
t = 1
e = 3
v = 1.
Hope this helps! -------------------------------- Gud Luck
steeve:
i like ur class and ur string too
Similar questions