ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2012 ICSE Computer Science Paper



Share with a Friend

Solved 2012 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Double Letter Sequences in a String Program - ICSE 2012 Computer Science

Write a program to accept a string. Convert the string to uppercase. Count and output the number of double letter sequences that exist in the string.
Sample Input: “SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE”
Sample Output: 4

import java.util.Scanner; class Sequence{ public static void main(String args[]){ Scanner in = new Scanner(System.in); System.out.print("Enter the string: "); String s = in.nextLine().toUpperCase(); int count = 0; for(int i = 0; i < s.length() - 1; i++){ char a = s.charAt(i); char b = s.charAt(i + 1); if(a == b) count++; } System.out.println(count); } }

Output

 
 OUTPUT : 
Enter the string: SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE
4