import java.util.Scanner;
class Project14
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a sentence");
String s=sc.nextLine().toUpperCase();
char ch=s.charAt(s.length()-1);
if(ch!='?' && ch!='!' && ch!='.')
{
System.out.println("Invalid Sentence");
System.exit(0);
}
int i,j=0,k=1,l=s.length();
String w="";
for(i=0;i<l-1;i++)
{
ch=s.charAt(i);
if(ch!=' ')
w+=ch;
}
l=w.length();
for(i=0;i<l;i++)
{
ch=w.charAt(i);
if(i==j)
{
System.out.print(ch+" ");
k++;
j+=k;
}
else
System.out.print(ch);
}
}
}
class Project14
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a sentence");
String s=sc.nextLine().toUpperCase();
char ch=s.charAt(s.length()-1);
if(ch!='?' && ch!='!' && ch!='.')
{
System.out.println("Invalid Sentence");
System.exit(0);
}
int i,j=0,k=1,l=s.length();
String w="";
for(i=0;i<l-1;i++)
{
ch=s.charAt(i);
if(ch!=' ')
w+=ch;
}
l=w.length();
for(i=0;i<l;i++)
{
ch=w.charAt(i);
if(i==j)
{
System.out.print(ch+" ");
k++;
j+=k;
}
else
System.out.print(ch);
}
}
}
No comments:
Post a Comment