Advertisement
NicholasCSW

StringArraySearchTestingGround

Mar 26th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.31 KB | None | 0 0
  1. /**
  2.  * Searches an string array yo
  3.  *
  4.  * @author Nitin Armstrong (the one and only)
  5.  * @version 4.20
  6.  */
  7. import java.io.*;
  8. import java.util.Scanner;
  9. public class NitinsCode {
  10.     public static void main(String [] args) {
  11.       ScansADoc();
  12.       String [] stringDoc = new String [ScansADoc()];
  13.       System.out.println("Welcome to the ARK, I am Elytra, ready to guide you");
  14.       System.out.println("Input your word below now");
  15.       compareStrings(stringDoc);
  16.      
  17.      
  18. }
  19.     public static int ScansADoc() {
  20.        int y = 0;
  21.         try {
  22.             Scanner scan = new Scanner(new BufferedReader(new FileReader("words.txt")));
  23.             int size = 0;
  24.             while(scan.hasNext()) {
  25.                 size++;
  26.                 scan.next();
  27.             }
  28.             String[] words = new String [size];
  29.             scan.close();
  30.             scan = new Scanner(new BufferedReader(new FileReader("words.txt")));
  31.            
  32.             while(scan.hasNext()) {
  33.                 words[y] = scan.next();
  34.                 y++;
  35.             }
  36.          
  37.            
  38.            
  39.             String myWord = "Will";
  40.            
  41.             if (myWord.compareToIgnoreCase(words[10]) < 0) {
  42.                 /**
  43.                  * This means myWord is less than words[10]
  44.                  */
  45.             }
  46.            
  47.            
  48.            
  49.            
  50.         } catch (Exception e) {
  51.             System.out.println("Valve Anti Cheat has Banned you for" + e.getMessage());
  52.         }
  53.         return (y);
  54. }
  55. public static void compareStrings(String [] stringDoc) {
  56.    Scanner scan2 = new Scanner(System.in);
  57.     scan2.next();
  58.     String a = scan2.next();
  59. String b = stringDoc[stringDoc.length/2];
  60.     for (int x = 0;x < 10; x++ ){
  61.     if (a.compareToIgnoreCase(b) < 0) {
  62.      bPositive(stringDoc);
  63.     }
  64.     else if (a.compareToIgnoreCase(b) > 0) {
  65.      bNegative(stringDoc);
  66.     }
  67.     else if (a.compareToIgnoreCase(b) == 0) {
  68.      System.out.println("The Word you specified is in the array");
  69.      break;
  70.     }
  71.        
  72. }
  73. }
  74. public static String bPositive(String [] stringDoc) {
  75.     String b = stringDoc[stringDoc.length/2 + 1];
  76.              
  77.     return(b);
  78.  
  79. }
  80. public static String bNegative(String [] stringDoc) {
  81.     String b = stringDoc[stringDoc.length/2 -1];
  82.    
  83.     return(b);
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement