Write a program that takes a string and checks whether the first or the second character or both is the letter 'x' or not. If so then omit those characters and print the rest of the string. Else print the original string unchanged. If the output string is empty print 0. Input specification: The input consists of a single string as an input. Output Specification: The output is a single string based on the input
Answers
Answered by
7
import java.util.Scanner;
class StringManipulation
{
public static void main()
{
Scanner sc=new Scanner(System.in);
String a,s="";
int i,l;
System.out.println("Enter a string");
a=sc.nextLine();
l=a.length();
for(i=0;i<l;i++)
{
if(i==0 || i==1){
if(a.charAt(i)=='x')
continue;
}
s=s+a.charAt(i);
}
if(s.equals(""))
System.out.println("0");
else
System.out.println(s);
}
}
class StringManipulation
{
public static void main()
{
Scanner sc=new Scanner(System.in);
String a,s="";
int i,l;
System.out.println("Enter a string");
a=sc.nextLine();
l=a.length();
for(i=0;i<l;i++)
{
if(i==0 || i==1){
if(a.charAt(i)=='x')
continue;
}
s=s+a.charAt(i);
}
if(s.equals(""))
System.out.println("0");
else
System.out.println(s);
}
}
Similar questions
Geography,
8 months ago
Physics,
8 months ago
Science,
8 months ago
CBSE BOARD X,
1 year ago
Math,
1 year ago