Advertisements
Advertisements
Question
Write a program for the following.
Input a string and print the characters that are not alphabets followed by the alphabets in it.
Code Writing
Advertisements
Solution
import java.util.*;
class clTask
{
void main()
{
String s1 = “", s2 = “", s3="",
Scanner sc = new Scanner(System.in);
char ch1, ch2;
int count = 0;
System.out.print(" Enter a sentence : ");
s1 = sc.nextLine();
for(int j = 0; j <= s1.length() - 1; j++)
{
ch1 = s1.charAt(j);
if(ch1'A' &&ch1<='Z' || ch1='a' && chl<='7(
{
s2 = s2 + ch1;
}
else
{
s3 = s3 + ch1;
}
}
s3 = s3 + s2;
System.out.println("New String is: "+ s3);
}
}
Output:
Enter a sentence : MHBLP,68/5,LANE#3,KONKAN
New String is :,68/5,#3,MHBLPLANEKONKAN
shaalaa.com
Is there an error in this question or solution?
