Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Scanner;
  3.  
  4. public class ScanStrings
  5. {
  6. public static void main (String [] args) {
  7. stringSearch();
  8. String [] stringWing = new String [stringSearch()];
  9. }
  10. public static int stringSearch() {
  11. int y = 0;
  12. try {
  13. Scanner scan = new Scanner(new BufferedReader(new FileReader("words.txt")));
  14. int size = 0;
  15.  
  16. while(scan.hasNext()) {
  17. size++;
  18. scan.next();
  19. }
  20. String[] words = new String [size];
  21. scan.close();
  22. scan = new Scanner(new BufferedReader(new FileReader("words.txt")));
  23.  
  24. while(scan.hasNext()) {
  25. words[y] = scan.next();
  26. y++;
  27. }
  28.  
  29.  
  30.  
  31. String myWord = "Wingle";
  32.  
  33. if (myWord.compareToIgnoreCase(words[10]) < 0) {
  34. /**
  35. * This means myWord is less than words[10]
  36. */
  37. }
  38.  
  39.  
  40.  
  41.  
  42. } catch (Exception e) {
  43. System.out.println("System failure. Delete system 32(Its useless anyway). " + e.getMessage());
  44. }
  45.  
  46. return(y);
  47. }
  48. public static void compareStrings() {
  49. String a = "blah";
  50. String b = "Thingy";
  51.  
  52. if (a.compareTo(b) < 0) {
  53. //This will happen if a is less than b
  54. //HOWEVER, compareTo thinks all upper case characters
  55. //are less than ALL lower case characters
  56. //so a.compareTo(b) will actually give a positive number
  57. }
  58. if (a.compareToIgnoreCase(b) < 0) {
  59. //This will work as expected
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement