Sip 4 - A) Write a java program to display alternate character from a given string.[

 Solution: 

import java.util.Scanner;
class Slip4A {
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        
        try {
            System.out.print("Enter String : ");
            String str = scan.nextLine();
            for(int i=0;i<str.length();i+=2) {
                System.out.print(" " + str.charAt(i));
            }
        } catch (Exception e) {}
    }
}

Output: 

Output_pic

Post a Comment

0 Comments