Program:
public class Series {
public static void main(String arg[]){
String str = "yuwetabcdefgrqwyu";
System.out.println(str);
char ch[]= str.toCharArray();
char result[] = new char[20];
int c=0, f=0;
result[0]=ch[0];
if(ch[1] == result[0]+1)
c++;
for(int i=1;i<ch.length-1;i++){
if((ch[i] == ch[i-1]+1) || (ch[i] == ch[i+1]-1)){
result[c++] = ch[i];
}
}
if(ch[ch.length-1] == result[c-1]+1)
result[c++] = ch[ch.length-1];
System.out.println(String.valueOf(result));
}
}
Input:
yuwetabcdefgrqwyu
Output:
abcdefg
public class Series {
public static void main(String arg[]){
String str = "yuwetabcdefgrqwyu";
System.out.println(str);
char ch[]= str.toCharArray();
char result[] = new char[20];
int c=0, f=0;
result[0]=ch[0];
if(ch[1] == result[0]+1)
c++;
for(int i=1;i<ch.length-1;i++){
if((ch[i] == ch[i-1]+1) || (ch[i] == ch[i+1]-1)){
result[c++] = ch[i];
}
}
if(ch[ch.length-1] == result[c-1]+1)
result[c++] = ch[ch.length-1];
System.out.println(String.valueOf(result));
}
}
Input:
yuwetabcdefgrqwyu
Output:
abcdefg
Read , Learn & Practice most Expected GK General Awareness Questions and Answers for various interviews & exams like GATE, IBPS, SBI, SSC, RRB, RBI etc.....
ReplyDeletehttp://www.gkindiaonline.com