-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterAndFrequency.java
More file actions
38 lines (35 loc) · 1.02 KB
/
Copy pathCharacterAndFrequency.java
File metadata and controls
38 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.*;
public class CharacterAndFrequency
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String str = in.next();
Character letter=' ';
String number = "";
for(int i=0;i<str.length();i++)
{
if(!(str.charAt(i) >= '0' && str.charAt(i) <= '9')) //if alphabet
{
if(!number.equals(""))
{
int n = Integer.parseInt(number);
for(int j=0;j<n;j++)
{
System.out.print(letter);
}}
letter = str.charAt(i);
number = "";
}
else{ //if number
number = number + (str.charAt(i) + "");
}
}
int n = Integer.parseInt(number);
for(int j=0;j<n;j++)
{
System.out.print(letter);
}
in.close();
}
}