Advertisement
Guest User

assignment 4

a guest
Oct 31st, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.Math;
  3.  
  4.  
  5. class main {  
  6. public static void main(String[] args)
  7. {
  8.     Scanner Scan = new Scanner(System.in);
  9.    
  10.     System.out.println("Please enter a tweet:");
  11.     int i = 0;
  12.     int hashtags = 0;
  13.     int at = 0;
  14.     int links = 0;
  15.     String tweet = Scan.nextLine();
  16.     if (tweet.length()<=140){
  17.         System.out.println("Length Correct");
  18.         while (i <= tweet.length()){
  19.            
  20.             if (tweet.length() > i+1 ){
  21.                 if (tweet.charAt(i) == '#' && (tweet.charAt(i+1) != ' ' || tweet.charAt(i+1) != '\t')){
  22.                     hashtags++;
  23.                 }
  24.                 if (tweet.charAt(i) == '@' && (tweet.charAt(i+1) != ' ' || tweet.charAt(i+1) != '\t')){
  25.                     at++;
  26.                 }
  27.            
  28.             }
  29.            
  30.             if (tweet.length() > i+7 )
  31.             if (tweet.substring(i, i+7).toUpperCase().equals("HTTP://")){
  32.                 links++;
  33.                
  34.             }
  35.                
  36.             i++;
  37.            
  38.            
  39.         }
  40.     System.out.println("length:" + i + "");
  41.     System.out.println("Number of Hashtags:" + hashtags + "");
  42.     System.out.println("Number of Attributions:" + at + "");
  43.     System.out.println("Number of Links:" + links + "");
  44.     } else {
  45.         System.out.println("Excess Characters: "  + (tweet.length() - 140));
  46.     }
  47.    
  48.    
  49.  
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement