Created
August 30, 2016 00:20
-
-
Save rooksoto/216d6b3dd425961354e34ee748e7afcd to your computer and use it in GitHub Desktop.
In class exercises for 08.29 - Rafael Soto, 3327
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package nyc.c4q.rafaelsoto; | |
public class Main { | |
public static void main(String[] args) { | |
//Q1. Triangle | |
drawTriangle(4); | |
System.out.print(""); | |
//Q2. Twitter | |
twitterMentions("@MMViverito @C4QNYC @PerScholas launch task force on diversity, inclusion & equity in NYC's tech sector http://bit.ly/2bcfygs #NYCCLabs"); | |
} | |
//Q1. Triangle Function | |
public static void drawTriangle(int size) { | |
String triangleBuilder = "#"; | |
for (int i = 0; i < size; i++) { | |
System.out.println(triangleBuilder); | |
triangleBuilder += "#"; | |
} | |
} | |
//Q2. Twitter Function | |
public static void twitterMentions(String tweet) { | |
String twitterMentionsBuilder = ""; | |
String twitterHashtagBuilder = ""; | |
for (int i = 0; i < tweet.length(); i++) { | |
if (tweet.charAt(i) == '@') { | |
while ((tweet.charAt(i) != ' ') && i != tweet.length() -1) { | |
twitterMentionsBuilder += tweet.charAt(i); | |
i++; | |
} | |
twitterMentionsBuilder += ' '; | |
} else if (tweet.charAt(i) == '#') { | |
while ((tweet.charAt(i) != ' ') && i != tweet.length() -1) { | |
twitterHashtagBuilder += tweet.charAt(i); | |
i++; | |
} | |
twitterHashtagBuilder += ' '; | |
} else { | |
i++; | |
} | |
} | |
System.out.println("Mentions: " + twitterMentionsBuilder + "Hashtags: " + twitterHashtagBuilder); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment