forked from alexhsamuel/AC3.3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeekTwoReview.java
More file actions
94 lines (80 loc) · 2.71 KB
/
Copy pathWeekTwoReview.java
File metadata and controls
94 lines (80 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String hello = "Hello";
printHashtags("@c4q #rocks #code #tech stuff goes here");
// System.out.println(hello.charAt(7));
// twitterMentions("@c4q #rocks #code #tech stuff goes here");
twitterMentionsArray("@c4q #rocks #code #tech stuff goes here");
}
public static void drawTriangle (int size) {
String triangleString = "";
for (int i = 0; i < size; i++) {
triangleString += "#";
System.out.println(triangleString);
}
}
public static void drawTriangleWithWhile(int size){
String triangleString = "";
int i = 0;
while(i < size) {
triangleString = triangleString + "#";
System.out.println(triangleString);
i++;
}
}
public static void printHashtags(String tweet){
Scanner scanner = new Scanner(tweet);
while(scanner.hasNext()){
String word = scanner.next();
if(word.charAt(0) == '@' || word.charAt(0) =='#'){
System.out.println(word);
}
}
}
public static void twitterMentionsArray(String tweet){
String[] words = tweet.split(" ");
String mentions = "Mentions: ";
String hashtags = "Hashtags:";
for(int i = 0; i < words.length; i++){
String word = words[i];
if(word.charAt(0) == '#'){
hashtags += word + " ";
}else if(word.charAt(0) == '@'){
mentions += word + " ";
} else{
continue; //do nothing;
}
}
System.out.println(mentions);
System.out.println(hashtags);
}
public static void twitterMentions(String tweet){
String mentions = "";
String hashtags = "";
for(int i = 0; i < tweet.length(); i++){
char c = tweet.charAt(i);
switch (c){
case '@':
while(tweet.charAt(i) != ' ' && i < tweet.length()) {
mentions += tweet.charAt(i);
i++;
}
break;
case '#':
while(c != ' ' && i < tweet.length()){
hashtags += tweet.charAt(i);
i++;
if(tweet.charAt(i) == ' '){
break;
}
}
break;
default: continue;
//fixme any letter thats not @ or #
}
}
System.out.println(mentions);
System.out.println(hashtags);
}
}