Advertisement
TheEpicKiller

Assignment 4 WIP 6

Oct 29th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.Math;
  3.  
  4. class Main {
  5. public static void main(String[] args) {
  6. Scanner scan = new Scanner (System.in);
  7. System.out.println("Please enter a tweet:");
  8. String input = scan.nextLine();
  9. int length = input.length();
  10. int count = 0;
  11. int hashtags = 0, attributions = 0, links = 0;
  12. char letter;
  13. int linkcount = count;
  14.  
  15. if (length >= 140)
  16. {
  17. System.out.println("Excess Characters: " + (length - 140));
  18. }
  19.  
  20. else
  21. {
  22. while (count < length)
  23. {
  24. letter = input.charAt(count);
  25.  
  26. if (letter == '#')
  27. {
  28. if (input.startsWith("# ", count) || input.startsWith("#\t", count)) {
  29. linkcount++;
  30. count++;
  31. }
  32. else {
  33. hashtags++;
  34. linkcount++;
  35. count++;
  36. }
  37.  
  38. }
  39.  
  40. if (letter == '@')
  41. {
  42. if(input.startsWith("@ ", count) || input.startsWith("@\t", count)) {
  43. linkcount++;
  44. count++;
  45. }
  46. else {
  47. attributions++;
  48. linkcount++;
  49. count++;
  50. }
  51. }
  52.  
  53. if (letter == 'h')
  54. {
  55. if (input.startsWith("http://", count))
  56. {
  57. links++;
  58. count++;
  59. }
  60. }
  61.  
  62. if (letter == 'H')
  63. {
  64. if (input.startsWith("http://"))
  65. {
  66. links++;
  67. linkcount++;
  68. count++;
  69. }
  70. else {
  71. count++;
  72. }
  73. }
  74. else
  75. {
  76. count++;
  77. }
  78. //if (count == length && input.startsWith("#", count)){
  79. // hashtags--;
  80. //}
  81. }
  82.  
  83.  
  84. System.out.println("Length Correct");
  85. System.out.println("Number of Hashtags: " + hashtags);
  86. System.out.println("Number of Attributions: " + attributions);
  87. System.out.println("Number of Links: " + links);
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement