abhirajpande
BAN USER
Forum Posts (1)
Comments (3)
Reputation 10
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Java code
void printLargetNumber(int[] array) {
String[] numbers = new String[10];
for (int i=0; i<array.length; i++) {
String number = array[i] + "";
for (int j=0; j<number.length(); j++) {
numbers[number.charAt(j) - '0'] += number.charAt(j) + "";
}
}
for (int i=9; i>=0; i--) {
if (numbers[i].length() > 0)
System.out.print(numbers[i]);
}
}
Comment hidden because of low score. Click to expand.
0
of 2 vote
Traverse the integer array. While traversing find out number of 9s, 8s, 7s and so on. Finally print a string with number of 9s found + number of 8s found and so on
- abhirajpande December 30, 2011Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
public class StringAsAlphabetFB {
- abhirajpande April 27, 2012void sortAndSum(String str) {
int[] array = new int[26];
int sum = 0;
for (int i=0; i<26;i++)
array[i] = 0;
for (int i=0; i<str.length(); i++) {
str = str.toLowerCase();
char c = str.charAt(i);
if (c>='a' && c<='z') {
array[c-'a']++;
}
else if (c>='0' && c<='9') {
sum += Integer.parseInt(c+"");
}
}
for (int i=0; i<26; i++) {
while(array[i]-- > 0)
System.out.print((char) ('a' + i));
}
System.out.println(sum);
}
public static void main(String[] args) {
StringAsAlphabetFB s = new StringAsAlphabetFB();
s.sortAndSum("zertyAB4ER69");
}
}