Advertisement
Arush22

Untitled

May 8th, 2019
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. package Suarez;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.util.Scanner;
  5. public class dataReader {
  6. public static void main(String[] args) throws IOException {
  7.  
  8. try {
  9. int n = 0;
  10. File fileInput = new File("C:\\Users\\Arush\\IdeaProjects\\9th Grade Tri2\\src\\Suarez\\data");
  11. Scanner input = new Scanner(fileInput);
  12. while(input.hasNext()){
  13. String line = input.nextLine();
  14. Scanner liner = new Scanner(line);
  15. while(liner.hasNextInt()){
  16. n = liner.nextInt();
  17. System.out.println(n);
  18. }
  19. }
  20. }
  21. catch(IOException ioe){
  22. ioe.printStackTrace();
  23. }
  24.  
  25.  
  26. }
  27. }
  28.  
  29.  
  30.  
  31. data.txt
  32. aadsfa
  33. adfadf
  34. 34
  35. 45
  36. 6
  37. 734
  38. asdfa
  39.  
  40.  
  41.  
  42.  
  43. package Suarez;
  44. import java.util.*;
  45. import java.io.*;
  46. import java.util.NoSuchElementException;
  47. public class C {
  48. public static void main(String[] args) {
  49.  
  50. Scanner parse = new Scanner ("A-B-C-D");
  51. String s = "";
  52. int i = 0;
  53. boolean switcher = false;
  54. parse.useDelimiter("-");
  55. while(switcher == false) {
  56. if(parse.next().equals("C")){
  57. System.out.println("C");
  58. switcher = true;
  59. }
  60. }
  61. }
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. package Suarez;
  69. import java.io.*;
  70. import java.nio.file.InvalidPathException;
  71. import java.util.*;
  72. public class printData {
  73. public static void main(String[] args) throws IOException{
  74. try {
  75. Scanner file26 = new Scanner(new File("C:\\Users\\Arush\\IdeaProjects\\9th Grade Tri2\\src\\Suarez\\data2"));
  76.  
  77. //Answer to problem 26
  78. for (int i = 0; i < 2; i++) {
  79. System.out.println(file26.nextLine());
  80. }
  81. }
  82. catch(IOException ioe){
  83. System.out.println(ioe.getMessage());
  84. }
  85.  
  86. //Answer to problem 27
  87. try{
  88. Scanner file27 = new Scanner(new File("C:\\Users\\Arush\\IdeaProjects\\9th Grade Tri2\\src\\Suarez\\data2"));
  89. int i = 0;
  90. while(file27.hasNextLine()) {
  91. i++;
  92. }
  93. String [] fileArray = new String [i];
  94. String temp = "";
  95. String convert = "";
  96.  
  97. for(int k = 0; k < fileArray.length; k++){
  98. convert = file27.nextLine();
  99. fileArray[k] = convert;
  100. }
  101.  
  102.  
  103. for(int f = 0; f < fileArray.length-1; f++) {
  104. for(int j = 0; j < fileArray.length-1; j++) {
  105. if (fileArray[j].compareTo(fileArray[j + 1]) < 0) {
  106. temp = fileArray[j];
  107. fileArray[j] = fileArray[j + 1];
  108. fileArray[j + 1] = temp;
  109. }
  110.  
  111. }
  112. }
  113.  
  114. for(int n = 0; n < fileArray.length; n++) {
  115. System.out.print(fileArray[n] + " ");
  116. }
  117. }
  118. catch(InvalidPathException ipe){
  119. System.out.println(ipe.getMessage());
  120. }
  121. catch(IOException ioe){
  122. System.out.println(ioe.getMessage());
  123. }
  124. catch(SecurityException se){
  125. System.out.println(se.getMessage());
  126. }
  127.  
  128. //Answer to problem 28
  129. try
  130. {
  131. Scanner file28 = new Scanner(new File("C:\\Users\\Arush\\IdeaProjects\\9th Grade Tri2\\src\\Suarez\\data2"));
  132. String result = "";
  133. while(file28.hasNextLine()) {
  134. result += file28.nextLine() + " ";
  135. }
  136. System.out.println(result);
  137. }
  138. catch (IOException ioe) {
  139. ioe.printStackTrace();
  140. }
  141.  
  142. //Answer to problem 29
  143. try
  144. {
  145. Scanner file29 = new Scanner(new File("C:\\Users\\Arush\\IdeaProjects\\9th Grade Tri2\\src\\Suarez\\data2"));
  146. String result = "";
  147. while(file29.hasNextLine()) {
  148. String line = file29.nextLine();
  149. if(line.length() >= 2) {
  150. if (line.substring(0,2).equalsIgnoreCase("sp")) {
  151. result += line + " ";
  152. }
  153. }
  154. }
  155. System.out.println(result);
  156. file29.close();
  157. }
  158. catch (IOException ioe) {
  159. ioe.printStackTrace();
  160. }
  161. }
  162. }
  163.  
  164.  
  165. data2.txt
  166. Java
  167. Illuminated
  168. Programming
  169. Is Not A
  170. Spectator
  171. Sport
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement