Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shavit Borisov
- // CW
- import java.util.Scanner;
- public class StringLastTwoCharacters {
- public static void main(String[] args)
- {
- Scanner in = new Scanner (System.in);
- final int STRING_SIZE = 20;
- String input;
- int counter = 0;
- System.out.printf("Enter a string, %d characters long:\n", STRING_SIZE);
- input = in.nextLine();
- char one = input.charAt(STRING_SIZE - 2);
- char two = input.charAt(STRING_SIZE - 1);
- for(int i = 0; i < STRING_SIZE - 2; i++)
- if((input.charAt(i) == one) && (input.charAt(i + 1) == two))
- counter++;
- System.out.printf("The number of '%c%c' pairs is %d.", one, two, counter);
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement