Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.lang.Math;
- class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner (System.in);
- System.out.println("Please enter a tweet:");
- String input = scan.nextLine();
- int length = input.length();
- int count = 0;
- int hashtags = 0, attributions = 0, links = 0;
- char letter;
- int linkcount = count;
- if (length >= 140)
- {
- System.out.println("Excess Characters: " + (length - 140));
- }
- else
- {
- while (count < length)
- {
- letter = input.charAt(count);
- if (letter == '#')
- {
- if (input.startsWith("# ", count) || input.startsWith("#\t", count)) {
- linkcount++;
- count++;
- }
- else {
- hashtags++;
- linkcount++;
- count++;
- }
- }
- if (letter == '@')
- {
- if(input.startsWith("@ ", count) || input.startsWith("@\t", count)) {
- linkcount++;
- count++;
- }
- else {
- attributions++;
- linkcount++;
- count++;
- }
- }
- if (letter == 'h')
- {
- if (input.startsWith("http://", count))
- {
- links++;
- count++;
- }
- }
- if (letter == 'H')
- {
- if (input.startsWith("http://"))
- {
- links++;
- linkcount++;
- count++;
- }
- else {
- count++;
- }
- }
- else
- {
- count++;
- }
- //if (count == length && input.startsWith("#", count)){
- // hashtags--;
- //}
- }
- System.out.println("Length Correct");
- System.out.println("Number of Hashtags: " + hashtags);
- System.out.println("Number of Attributions: " + attributions);
- System.out.println("Number of Links: " + links);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement