At some point I have trouble programming ROT13 in Java. So the User shall write whatever he wants and the programm should rewrite it in ROT13. So here´s my programm until now:
import java.io.*;
public class rot13
{
public static void main (String [] args) throws IOException
{
BufferedReader myInput = new BufferedReader (new InputStreamReader (System.in));// Buffered Reader reads the number inputed
String key [] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
String keyA [] = {"N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L","M"};
String letter;
System.out.println("Enter a phrase:");
String phrase = myInput.readLine();
int y = 0, i = 0;
while ( y <= phrase.length()){
letter = Character.toString(phrase.charAt(y));
while(i <= y){
if (letter != key[i]){
keyA [i] = keyA[i];
}
i++;
}
System.out.println(keyA [i]);
y++;
}
}
}
The problem is the following:
It only does go for a few letters, but stops working after like 3 lines or rather after 3 latters and puts up errors which are:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 3
at java.lang.String.charAt(Unknown Source)
at rot13.main(rot13.java:19)
I´ve tried different words, but it keeps printing out the same problem. Does anyone knows how to fix it or at least a way to do it more proberly?
Thanks in advance!!
Why it doesn't work
import java.io.*;
public class rot13
{
public static void main (String [] args) throws IOException
{
BufferedReader myInput = new BufferedReader (new InputStreamReader (System.in));// Buffered Reader reads the number inputed
String key [] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
String keyA [] = {"N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L","M"};
String letter;
System.out.println("Enter a phrase:");
String phrase = myInput.readLine();
int y = 0, i = 0;
while ( y <= phrase.length()){
letter = Character.toString(phrase.charAt(y));
//Each time you go throught the first loop, you are comparing your actual position in the string and i
//But as you don't reset i back to 0, you only try to compare your previous index and your actual index : if y == 3, so i takes only the values 2 and 3
//Moreover, when y > 26, you try to access the key array outside of its bounds
while(i <= y){
// letter is a string so you should be using equals
if (letter != key[i]){
// You are putting the value at the i index in the i index, so you do basically nothing with this line
keyA [i] = keyA[i];
}
i++;
}
System.out.println(keyA [i]);
y++;
}
}
}
Alternative
Here's a solution you can use :
import java.io.*;
public class rot13 {
public static void main(String[] args) throws IOException {
BufferedReader myInput = new BufferedReader(new InputStreamReader(System.in));// Buffered Reader reads the number inputed
System.out.println("Enter a phrase:");
String input = myInput.readLine();
//We loop through every char in the string
for (char c : input.toCharArray()) {
//We check if the character is a letter, so we don't add the offset to special characters like space or dot
if (Character.isAlphabetic(c)) {
//Here we get the lower case version of the char and remove it 97, which is the ascii value of 'a'
//With this, we are mapping letters from a to z to numbers from 0 to 25
char lowerChar = (char) (Character.toLowerCase(c) - 97);
//We add the offset of 13
lowerChar += 13;
//We then use the modulo to move numbers higher than 15 back to the beginning
lowerChar %= 26;
//We finally come back to the ascii value of our lower case char
lowerChar += 97;
System.out.print(Character.isUpperCase(c) ? Character.toUpperCase(lowerChar) : lowerChar);
} else {
//If it's not a letter, we just print the char
System.out.print(c);
}
}
//We don't forget to close our BuffererReader
myInput.close();
}
}
This is a described version but you can shorten it by doing all the char operations on one line
Related
my question is if i have a string- with two types of chars in the string '#' and '.' and I want to count how many times I land on '#' if each time I move to the right 3 and down one.
for example the given string would look like the following:
...#.#.......##....#.......#...
.#....#.##.#..#.......#.....##.
#..#...##.####..###.....#......
..#...##...#...#.#......#...#.#
.##.##.#...#.....#.##..##......
.#...#.#.##.###..#...#...#.....
.#..##..#....##.##....##....##.
..#...##....#..###........##...
.#..#..#.#....#.#...#.#......#.
.##.....#...#..#..#..#...###...
.#...#....#..#...........###...
.....#...........##.#......#...
.....#....##......##..#.#......
-1//stops the checking
what should happen is the following, 0 means landed on a . and X means it landed on # which is when count should go up by one each time this happens:
...#.#.......##....#.......#...
.#.o..#.##.#..#.......#.....##.
#..#..0##.####..###.....#......
..#...##.0.#...#.#......#...#.#
.##.##.#...#0....#.##..##......
.#...#.#.##.###0.#...#...#.....
.#..##..#....##.##0...##....##.
..#...##....#..###...o....##...
.#..#..#.#....#.#...#.#.0....#.
.##.....#...#..#..#..#...##X...
.#...#....#..#...........###..0//notice here next round it will exceed
.....#...........##.#......#.....0..#...........##.#......#...//line get doubled as if returning to beginning of the
.....#....##......##..#.#...........X....##......##..#.#......//same here
-1//to stop
so at the start, I move to the third index and down 1 which is to the next row and I check if that char is '#' if yes count++
so in this example- it moves three so the first row moves to ... then goes down to the next row which will be index 3 which in this case is .#. so the third is. and so on. and if it landed on # count++.
here's my code but it doesn't seem to work-
public static Scanner reader = new Scanner(System.in);
public static void main(String[] args) {
String a = "";//starts empty
int cnt = 0, b = 0;//cnt++ if '#', b helps us move 3 to the right each time
a = reader.nextLine(); //gets the string
if (b + 3 > a.length() - 1) {//checks that the length when moving 3 doesn't exceed string length
b = 0;// if it does exceed then go all the way to the left of the string
}
b += 3;//move right 3
a = reader.nextLine(); //get next line from the input
while (a != "-1") {//until there is -1 (to stop getting input) it continues to check
char c = a.charAt(b -
1);//takes whats at place b(-1 is because first index is 0 and not1) and note this is three to the right and after it moves down a row!// is line 23
if (c == '#' && a != "") {//checks if string isn't empty and if the char equals #
cnt++;//if yes count++
}
if (b + 3 > a.length() - 1) {//explained above
b = 0;
}
b += 3;
a = reader.nextLine();
}
System.out.println(cnt);
}
errors I get is the following:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 26
at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:47)
at java.base/java.lang.String.charAt(String.java:702)
at q.qq.main(Advent3.java:23)
help would be appreciated. let me know if something isn't clear or even how to improve:) thanks
code after talking in chat and trying to improve:
public class Advent3 {
public static Scanner reader= new Scanner(System.in);
public static void main(String[] args){
int b=4,cnt=0,line=1,s;
String str="";
char charsign;
str=reader.nextLine();
s=str.length();
str=reader.nextLine();
while(str!=""||str!="-1") {
line++;
s=str.length();
if(b%str.length()==0) {
charsign= str.charAt(10);
}
else {
charsign= str.charAt(b%str.length()-1);
}
if(charsign=='#') {
cnt++;
System.out.println(cnt);
}
b+=3;
str=reader.nextLine();
}
System.out.println(str);
System.out.println(cnt);
}
}
the code itself works and I think I'm very close but it doesn't print the right answer!
I'm stuck so help would be much-appreciated thanks!
public static int count(Scanner scan) {
int res = 0;
int col = -1;
String str;
boolean check = false;
while (!"-1".equals(str = scan.nextLine())) {
if (col >= str.length())
col %= str.length() - 1;
if (check && str.charAt(col) == '#')
res++;
col += 3;
check = true;
}
return res;
}
Demo:
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(count(scan)); // 5
}
Input:
...#.#.......##....#.......#...
.#....#.##.#..#.......#.....##.
#..#...##.####..###.....#......
..#...##...#...#.#......#...#.#
.##.##.#...#.....#.##..##......
.#...#.#.##.###..#...#...#.....
.#..##..#....##.##....##....##.
..#...##....#..###........##...
.#..#..#.#....#.#...#.#......#.
.##.....#...#..#..#..#...###...
.#...#....#..#...........###...
.....#...........##.#......#...
.....#....##......##..#.#......
-1
Output:
...#.#.......##....#.......#...
.#0...#.##.#..#.......#.....##.
#..#.0.##.####..###.....#......
..#...##0..#...#.#......#...#.#
.##.##.#...1.....#.##..##......
.#...#.#.##.##2..#...#...#.....
.#..##..#....##.#3....##....##.
..#...##....#..###..3.....##...
.#..#..#.#....#.#...#.#3.....#.
.##.....#...#..#..#..#...#4#...
.#...#....#..#...........###.4.
..4..#...........##.#......#...
.....5....##......##..#.#......
-1
5
I am trying to write a code which would count the number of words of a certain length in a file.
For example:
How are you?
would print:
Proportion of 3-letter words: 100% (3 words)
I want to count words of length 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13+
Can you please guide me?
I am NOT trying to find the number of words. I am already able to do with this code:
public static int WordCount() throws FileNotFoundException
{
File file = new File("sample.txt");
Scanner keyboard = new Scanner(new FileInputStream(file));
int count=0;
while(keyboard.hasNext())
{
keyboard.next();
count++;
}
return count;
}
I want to find words of a certain length.
UPDATE
I have written the following code:
public static int WordLengthCount() throws FileNotFoundException
{
File file = new File("hello.txt");
Scanner keyboard = new Scanner(new FileInputStream(file));
int count5 = 0;
int hell = 0; //This is just for the else command to compile
while(keyboard.hasNext())
{
if ( keyboard.next().length() == 5 )
{
count5++;
keyboard.next();
return count5;
}
} return hell;
}
You can use the length() method to count the number of characters in a string (word). From there on, it's just a matter of saving it somewhere. E.g., in Map:
public static Map<Integer, Integer> lengthCounts() throws FileNotFoundException
Map<Integer, Integer> countMap = new HashMap<>();
while(keyboard.hasNext())
{
String word = keyboard.next();
int length = word.length();
Integer currCount = countMap.get(length);
if (currCount == null) {
countMap.put (length, 1);
else {
countMap.put (length, currCount + 1);
}
}
return countMap;
}
Now you could check the number of words with any particular length, or even print all of them.
EDIT:
If the only thing you need is the percentage of words of a certain length, all you need are two counters - one for the words of that length, and one for all the words:
public static double lengthPercentage(int requiredLength) throws FileNotFoundException
int allWords = 0;
int requiredWords = 0;
while(keyboard.hasNext())
{
String word = keyboard.next();
int length = word.length();
if (length == requiredLength) {
++requiredWords;
}
++allWords;
}
// implicit assumption: there's at least on word in the file
return ((double) requiredWords) / allWords;
}
File file = new File("sample.txt");
Scanner keyboard = new Scanner(new FileInputStream(file));
int count=0;
while(keyboard.hasNext())
{
keyboard.next();
// Use a hash map
// Check the string length and add it to the hash map by checking it already exists. If already exists then get the actual value from hashmap and increment it by one and save it again to the map.
count++;
}
So that your final output will be of map with one letter string count, two letter string count etc..
The other answers are great, but if you are trying to find words of a specific length in a file and you don't like the answers above, then you could also try REGEX. You can test each word and then do what you want with it. If you are looking for a count of words in a file of each length, I think the answer above is better, but if you're looking to detect a word of a specific length you could use .length() or the regex below. Using a strings .lenght() function in my opinion is better, but I'm just giving you an alternative answer and example.
I'll put a small example below.
public class Words{
public static void main(String [] args){
String [] words = {"Pizzaaa", "Pizza", "Party"};
int fives = 0;
for( String s : words){
if(s.matches(".{5}")){
5++;
}
}
System.out.println(fives);
}
}
Or a better version:
public class Words{
public static void main(String [] args){
String [] words = {"Pizzaaa", "Pizza", "Party"};
int fives = 0;
for( String s : words){
if(s.length() == 5){
5++;
}
}
System.out.println(fives);
}
}
Edited Below: To demonstrate how it can be used in a file based loop
// other code needed
while(in.hasNext())
{
String s = in.next();
if(s.length() == 5)
fives++;
}
For example, I have text file named TextFile.txt at C:\ has content:
Ut porttitor libero sodales quam sagittis, id facilisis lectus semper.
and Java code:
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class Example {
public static void main(String[] args) throws IOException {
File file = new File("C:\\TextFile.txt");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
if (dis.available() != 0) {
// Get the line.
String s = dis.readLine();
// Put words to array.
String[] sParts = s.split(" ");
// Initialize word longest length.
int longestLength = 1;
for (String strx : sParts) { // Go through each sPart, the next one is called strx
// If the document has word longer than.
if (longestLength < strx.length())
// Set new value for longest length.
longestLength = strx.length();
}
// Because array index from "0".
int[] counts = new int[longestLength + 1];
for (String str : sParts) {
// Add one to the number of words that length has
counts[str.length()] += 1;
}
// We use this type of loop since we need the length.
for (int i = 1; i < counts.length; i++) {
System.out.println(i + " letter words: " + counts[i]);
}
}
}
}
// Result:
// 1 letter words: 0
// 2 letter words: 2
// 3 letter words: 0
// 4 letter words: 1
// 5 letter words: 0
// 6 letter words: 2
// 7 letter words: 2
// 8 letter words: 0
// 9 letter words: 3
I am having difficulty in the following, replacing certain characters from the string
There will be two inputs, first will be character and second will be string
then I need to replace all those characters from the string with it's position
for example ,
the input and output of my program are as follows which is absolutely correct as per the requirement
Input : i this is Ignite
( Here "i" is the first input and "this is Ignite" is the second input
Output : th2s 5s 8gn11te
Input : i this is ignite and i am pratik
Output : th2s 5s 8gn11te and 20 am prat30k
The replacement should not be case-sensitive.
I had written the following program but it's having some bugs, Bugs in the sense that I am actually doing some project online and the automated sytem is not accepting the program because of some logical error.The automated system does some test cases with different inputs and check the output ( not exceptions or invalid inputs) can someone help me identify it ?
import java.util.*;
import java.io.*;
class rplc
{
public static void main(String args[])
{
String str,temp="";
char ch, ch2;
int arr[]=new int[100];
int len,i,x=0;
Scanner input=new Scanner(System.in);
ch=input.next().charAt(0);
str=input.nextLine();
str=str.replaceAll("^\\s+","");
ch2=ch;
if(Character.isUpperCase(ch))
ch2=Character.toLowerCase(ch);
else if(Character.isLowerCase(ch))
ch2=Character.toUpperCase(ch);
len=str.length();
temp=str;
for(i=0;i<len;i++)
{
if(str.charAt(i)==(int)ch || str.charAt(i)==(int)ch2)
{
arr[x]=i;
x=x+1;
}
}
x=0;
for(i=0;i<len;i++)
{
if(str.charAt(i)==(int)ch || str.charAt(i)==(int)ch2)
{
temp=str.substring(0,i);
temp=temp+(arr[x]);
temp=temp+str.substring(i+1,len);
str=temp;
len=temp.length();
x=x+1;
}
}
System.out.print(temp);
}
}
Seems like your code should work. Just in case I tried writing a simpler program:
Scanner input=new Scanner(System.in);
char ch = Character.toLowerCase(input.next().charAt(0));
String str = input.nextLine().trim().toLowerCase();
input.close();
StringBuffer buf = new StringBuffer();
for (int i = 0; i < str .length(); i++) {
if (str.charAt(i) == ch) {
buf.append(i);
}
else {
buf.append(str.charAt(i));
}
}
System.out.println(buf.toString());
And the output seems to be same.
Perhaps your function should return the value instead of printing it?
From the comments I understand that there will be only 1 input from the user.
The following input:
i this is ignite and i am pratik
Where the first 'i' is the charcter which needs to be replaced in 'this is ignite and i am pratik'.
Modify following:
str=input.nextLine();
str=str.replaceAll("^\\s+","");
to
str = input.nextLine();
str = str.substring(1);
str = str.replaceAll("^\\s+", "");
Try Something like this,
Scanner s = new Scanner(System.in);
String Line = s.nextLine();
String ch = Line.substring(0,Line.indexOf(" ")).trim();
Line = Line.substring(Line.indexOf(" ")).trim();
String[] x= Line.split(ch);
String y="";
for(String t:x){
y=y.equals("")?t:y+y.length()+t;
}
System.out.println(y);
I did some code cleaning but the most important steps were to use a list of dynamic size instead of a fixed size array and a while-loop with dynamic termination instead of a for-loop. This is because the length of the output String will change (increase) when there a characters to be replaced at positions >9 and thus in your code the execution can stop in the middle of the result string and there are characters not being replaced.
There is even a special case, when the replaced character is a number itself. To avoid problems there I added this line
i = i + Integer.toString(list.get(pos)).length()-1;
in order to step over newly added number characters in the output String.
import java.util.*;
import java.io.*;
class rplc
{
public static void main(String args[])
{
List<Integer> list = new ArrayList<Integer>();
Scanner input=new Scanner(System.in);
char ch = input.next().charAt(0);
String str=input.nextLine().trim();
int len=str.length();
for(int i=0;i<len;i++)
{
if(str.charAt(i)==Character.toLowerCase(ch) || str.charAt(i)==Character.toUpperCase(ch))
{
list.add(i);
}
}
int pos = 0;
int i = 0;
while(i<str.length())
{
if(str.charAt(i)==Character.toLowerCase(ch) || str.charAt(i)==Character.toUpperCase(ch))
{
String start = str.substring(0,i)+Integer.toString(list.get(pos));
String end = i<=str.length() ? str.substring(i+1) : "";
i = i + Integer.toString(list.get(pos)).length()-1;
pos++;
str = start.concat(end);
}
i++;
}
System.out.print(str);
}
}
I can't see any special bugs. Could be that I lost sight of something. This is my first answer here and English is not my mother tongue, so please excuse any formal errors.
I liked the problem so I made my own answer. apologies for the dirty looking code. :)
Scanner input=new Scanner(System.in);
String firstInput=input.nextLine().charAt(0) + "";
//ensure its lower case
firstInput=firstInput.toLowerCase();
String secondInput=input.nextLine();
//ensure char in secondInput is lower cased too.
secondInput=secondInput.replaceAll(firstInput.toUpperCase(),firstInput);
String[] splitted=secondInput.split(firstInput);
String output="";
int current=0;
for(int i=0;i<splitted.length;i++){
String s=splitted[i];
current=current+ s.length();
if(i==splitted.length-1){
output=output+s;
}else{
output=output+s;
output=output+ current;
current++;
}
}
//edited part, as split doesn't split if firstinput is the last character of the string
if(secondInput.endsWith(firstInput)){
output=output+secondInput.length();
}
System.out.println(output);
I been trying write code that checks if a word is a word that the first letter and the last letter are the same. In essence, it's code that checks to see if a Word is a palindrome.
Code
import java.util.*;
public class Class1 {
static Scanner reader = new Scanner(System.in);
public static void main(String[] args) {
String n = reader.next();
boolean right = true;
for (int i=0; i<n.length();i++)
{
int f = n.length()-i;
if (n.charAt(i) != n.charAt(f -i))
{
right=false;
}
}
System.out.println("The word is " + right);
}
}
I get this error:
TT
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at java.lang.String.charAt(Unknown Source)
at Class1.main(Class1.java:12)
Thank you.
It's almost right, just int f = n.length()-i; should be int f = n.length()-1;.
n.length()-1 is the index of the last character in the string. So f-i will be the i-th character from the right.
Try this:
import java.util.*;
public class Class1 {
static Scanner reader = new Scanner(System.in);
public static void main(String[] args) {
String n = reader.next();
boolean right = true;
int f = n.length()-1;
for (int i=0; i<n.length();i++)
{
if (n.charAt(i) != n.charAt(f-i))
{
right=false;
}
}
System.out.println("The word is " + right);
}
}
Suppose take an example the length of String is 3 and when i reaches 2 then according to you f will be 1
then take this line n.charAt(f -i) it will be like charAt(1-2) so definately it will throw some exception
Try something like this
int s = n.length();
for (int i=0; i<(s/2)+1;++i) {
if (n.charAt(i) != n.charAt(s - i - 1)){
right=false;
}
}
System.out.println("The word is " + right);
Dont forget to debug the code to know about the flow only finding the solution is never going to help you
To add with other answers you don't need to loop through the whole string. you only need to loop through half of the string length to see if your string is a palindrome or not.
Suppose you are checking if madam is palindrome or not. You have to loop half of the length of madam that is 5/2 or 2 times only.
index0 m == m index4
index1 a == a index2
So here is the slightly modified code
for(int i = 0;i<n.length()/2;i++) {
if(n.charAt(i) != n.charAt(n.length()-1-i))
{
right=false;
}
}
The error you are getting is an index out of range, stating your input parameter for n.charAt(#) is outside n's index range, it being from 0 to n.length()-1
The error in your code however is at this point of the code:
int f = n.length()-i; //negate i from the length
if (n.charAt(i) != n.charAt(f -i)) //negate i from the already negated length
and the fix should be:
int f = n.length()-i-1;
if (n.charAt(i) != n.charAt(f))
I'm doing an assignment where I'll have to code a program to read in a string from user and print out the letters in the string with number of occurrences. E.g. "Hello world" in which it should print out "h=1 e=1 l=3 o=2 ... etc.", but mine only write "hello world" and the amount of letters in total. I can't use the hashmap function, only arrays. Can someone give me a hint or two on how to proceed from the written code below to get my preferred function? I don't understand exactly how to save the written input in array.
Here's my code so far.
public class CountLetters {
public static void main( String[] args ) {
String input = JOptionPane.showInputDialog("Write a sentence." );
int amount = 0;
String output = "Amount of letters:\n";
for ( int i = 0; i < input.length(); i++ ) {
char letter = input.charAt(i);
amount++;
output = input;
}
output += "\n" + amount;
JOptionPane.showMessageDialog( null, output,
"Letters", JOptionPane.PLAIN_MESSAGE );
}
}
You don't need 26 switch cases. Just use simple code to count letter:
String input = userInput.toLowerCase();// Make your input toLowerCase.
int[] alphabetArray = new int[26];
for ( int i = 0; i < input.length(); i++ ) {
char ch= input.charAt(i);
int value = (int) ch;
if (value >= 97 && value <= 122){
alphabetArray[ch-'a']++;
}
}
After done count operation, than show your result as:
for (int i = 0; i < alphabetArray.length; i++) {
if(alphabetArray[i]>0){
char ch = (char) (i+97);
System.out.println(ch +" : "+alphabetArray[i]); //Show the result.
}
}
Create an integer array of length 26.
Iterate each character of the string, incrementing the value stored in the array associated with each character.
The index in the array for each character is calculated by x - 'a' for lower case characters and x - 'A' for upper case characters, where x is the particular character.
You can create an Array which first element will represent 'a', second 'b', etc. If you need distinction between lower and upper cases than you can add it at the end. This array will have all values equals 0 at the beginning.
Then you iterate through your sentence and you increment required values on the array.
At the end you print all values that are > 0. Simple?
Let me know if you need more help
No you should not create an array of 26. This will break if the string contains unexpected characters. (ä, ö, ü anyone?)
As I pointed out im my comment use a Map. This will work forr all posible characters out there.
import java.io.*;
public class CharCount {
public static void main(String[] args) throws IOException
{
int i,j=0,repeat=0;
String output="",input;
char c=' ';
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter name ");
input=br.readLine();
System.out.println("entered String ->\""+input+"\"");
input=input.toLowerCase();
for(i=0;i<input.length();i++)
{
for(j=0;j<output.length();j++)
{
if(input.charAt(i)==output.charAt(j) || input.charAt(i)==c)
{
repeat=1;
break;
}
}
if(repeat!=1)
{
output=output+input.charAt(i);
}
repeat=0;
}
System.out.println("non-reepeated chars in name ->\""+output+"\"");
int count[]=new int[output.length()];
for(i=0;i<output.length();i++)
{
for(j=0;j<input.length();j++)
{
if(output.charAt(i)==input.charAt(j))
count[i]=count[i]+1;
}
}
for(i=0;i<output.length();i++)
System.out.println(output.charAt(i)+"- "+count[i]);
}
}