I have to create a program that accepts "tweets" from a user and validates it first to ensure that It tests that it is less than 140 characters.
If it is valid, then this number of hashtags (#), attribution symbols (@), and links ("http: //) are in the string, then prints them. My program hashtags and attribution Works, but not the link. How can I fix this code so that it works?
java.util.Scanner; class test {public static zero main (string [ ] Args) {Scanner Scan = New Scanner (System.); System Out.print ("Please Please Insert rewrite: "); string input = scan.nxine (); int length = input.length (); int count = 0; int hashtags = 0, attributes = 0, links = 0; four letters; if (length & 140) {System.out.println ("Extra Characters:" + (Length - 140)); and (while (calculated & lt; length) {letter = input.charAt (count); if (letter == '#') {Hashtags ++; count ++;} if (letter == '@') {attributions ++; count ++;} if (letter == 'h') {string test = input. Substring ( Calculation, calculation + 6); test = test.toLowerCase (); if (test == "http: //") {links ++; count ++;} and {count ++;}} and {count ++ ; }} System.out.println ("right length"); System.out.println ("Number of hashtags:" + hashtag); System.out.println ("Number of Attribution:" + Attribution); System.out.println ("Number of Links:" + Link); }}
I think your code will not work with links. Use regular expression instead of (if else) {} if () else {} . And keep in mind: a token (mention, hashtag, link) that includes other tokens.
Comments
Post a Comment