aabccdee
Find the used alphabets as abcde ?

Answers were Sorted based on User's Feedback



aabccdee Find the used alphabets as abcde ?..

Answer / vikas

1. Split the String into a String array.
2. Iterate over the String Array and add values into a Set(Duplicate values are not allowed).

Is This Answer Correct ?    2 Yes 0 No

aabccdee Find the used alphabets as abcde ?..

Answer / hitesh

public static void main(String[] args) {

String s1 = "aaabbccccaaa";
String s2 = " ";
for (int i = 0; i < s1.length(); i++) {
if (i == 0) {
s2 = s2.concat("" + (s1.charAt(i)));
}

if (s2.contains(s1.charAt(i) + "")) {
continue;
} else {
s2 = s2.concat("" + (s1.charAt(i)));
}
}
System.out.println(s2);
}

Is This Answer Correct ?    1 Yes 0 No

aabccdee Find the used alphabets as abcde ?..

Answer / deepu

package com.thread;
import java.util.*;
public class Test2 {





public static void main(String[] args) {
String str="aabbbcdabbheaa";
char[]chs=str.toCharArray();
List l1=new ArrayList();

for(Character ch:chs){
l1.add(ch);
 
}
Set s1=new TreeSet(l1);
System.out.println(s1);
}




}

Is This Answer Correct ?    1 Yes 0 No

aabccdee Find the used alphabets as abcde ?..

Answer / adarsh

Scanner sc=new Scanner(system.in);
Int i,j=0;
String S1=sc.next(),s2;
S2=s1charAt(0);
For(i=1;i<s1.length;i++)
{
If(s2.charAt(j).equals (s1.charAt(i))
Continue;
Else{
S2=s2.concat(s1.charAt(i));
j++;
}
}
Sop(j);
}


I m writing with my mobile phone so chuck the mistakes like upercase nd lowr case...

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More Core Java Interview Questions

What is the use of put method?

0 Answers  


Given a singly linked list, determine whether it contains a loop or not without using temporary space?

0 Answers   Global Logic,


If two threads call a static method at the same point of time, what will happen?

3 Answers   KPIT,


Considering notepad/ie or any other thing as process, what will happen if you start notepad or ie 3 times? Where 3 processes are started or 3 threads are started?

0 Answers  


Explain the importance of import keyword in java?

0 Answers  






what is the use of bean managed and container managed with example?

0 Answers   EDS,


Is void a type?

0 Answers  


My interview asked what is dynamic variable in java and where we use them.

2 Answers   IBM,


What is this keyword in java?

0 Answers  


Can classes declared using the abstract keyword cab be instantiated?

0 Answers   MCN Solutions,


What is difference between this and super keyword?

0 Answers  


What is the full form of jpeg?

0 Answers  


Categories