Guest User

Untitled

a guest
Jan 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. public class startSearch{
  2. String[] arr;
  3. startSearch(String[] arr){
  4. this.arr = arr;
  5. }
  6. void print(){
  7. String search = "";
  8. for(int i = 1;i<arr.length;i++){
  9. search = arr[i];
  10. }
  11. try {
  12. String y = new Scanner(new File("C:\Users\len\Desktop\none.txt")).useDelimiter("\Z").next();
  13. if (y.contains(search)) {
  14. System.out.println("File is contain your search:" + search);
  15. System.out.println(y);
  16. }
  17. }catch (Exception e){
  18. System.out.println(e);
  19. }
  20. }
  21.  
  22. public class startSearch{
  23. String[] arr;
  24. String help;
  25. startSearch(String[] arr){
  26. this.arr = arr;
  27. }
  28. void print(){
  29. String search = "";
  30. for(int i = 0;i<arr.length;i++){
  31. if(i%2==0) {
  32. help = arr[i] + " ";
  33. search += help;
  34. }else {
  35. search+=arr[i];
  36. }
  37. }
  38. try {
  39. String y = new Scanner(new File("C:\Users\len\Desktop\none.txt")).useDelimiter("\Z").next();
  40. if (y.contains(search)) {
  41. System.out.println("File is contain your search:" + search);
  42. System.out.println(y);
  43. }else{
  44. System.out.println("Your request did not found");
  45. }
  46. }catch (Exception e){
  47. System.out.println(e);
  48. }
  49. }
  50.  
  51. public class StartSearch {
  52. private static String[] arr;
  53. private final String PATH = "C:\Users\len\Desktop\none.txt";
  54.  
  55. StartSearch(String[] a) {
  56. arr = a;
  57. }
  58.  
  59. private static Boolean checkWord(String s) {
  60. int i = 0;
  61. while (i < arr.length && !arr[i].equals(s)) {
  62. i++;
  63. }
  64. return i < arr.length;
  65. }
  66.  
  67. void print() {
  68. try {
  69. List<String> fileList = Files.lines(Paths.get(PATH), StandardCharsets.UTF_8)
  70. .map(s -> s.split(" "))
  71. .flatMap(Arrays::stream)
  72. .filter(i -> !i.isEmpty())
  73. .collect(Collectors.toList());
  74.  
  75. if (fileList.stream().filter(StartSearch::checkWord).count() > 2) {
  76. System.out.println("File is contain your search:" + Arrays.toString(arr));
  77. System.out.println(fileList);
  78. }
  79. } catch (Exception e) {
  80. System.out.println(e);
  81. }
  82. }
  83. }
Add Comment
Please, Sign In to add comment