Consecutive letters in a sentence in Java

Write a program to print the consecutive letters in a sentence. Both input and output
     are considered in uppercase.

import java.util.*;
class Consecutive{
    public static void main(){
        Scanner sc=new Scanner(System.in);
        String str,s="";
        int i,l,j;
        System.out.println("Enter a sentence");
        str=sc.nextLine();
        str=str.toUpperCase();
        l=str.length();
        for(i=65;i<=90;i++){
            for(j=0;j<l;j++){
                if(str.charAt(j)==i){
                    s=s+str.charAt(j);
                    break;
                }//if
            }//for j
        }//for i
                System.out.println("The characters consecutively   "+s);
        }//End of main
    }//End of class
    OUTPUT---
Enter a sentence
A QUICK BROWN FOX JUMPS OVER THE LAZY DOG
The characters consecutively   ABCDEFGHIJKLMNOPQRSTUVWXYZ

Comments

Popular posts from this blog

Sort Boundary Elements Of A Matrix

Lucky Number In Java ISC

Program to fill a square matrix of size ‘n*n” in a circular fashion (clockwise) with natural numbers from 1 to n*n, taking ‘n’ as input.