Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Suarez;
- import java.io.File;
- import java.io.IOException;
- import java.util.Scanner;
- public class dataReader {
- public static void main(String[] args) throws IOException {
- try {
- int n = 0;
- File fileInput = new File("C:\\Users\\Arush\\IdeaProjects\\9th Grade Tri2\\src\\Suarez\\data");
- Scanner input = new Scanner(fileInput);
- while(input.hasNext()){
- String line = input.nextLine();
- Scanner liner = new Scanner(line);
- while(liner.hasNextInt()){
- n = liner.nextInt();
- System.out.println(n);
- }
- }
- }
- catch(IOException ioe){
- ioe.printStackTrace();
- }
- }
- }
- data.txt
- aadsfa
- adfadf
- 34
- 45
- 6
- 734
- asdfa
- package Suarez;
- import java.util.*;
- import java.io.*;
- import java.util.NoSuchElementException;
- public class C {
- public static void main(String[] args) {
- Scanner parse = new Scanner ("A-B-C-D");
- String s = "";
- int i = 0;
- boolean switcher = false;
- parse.useDelimiter("-");
- while(switcher == false) {
- if(parse.next().equals("C")){
- System.out.println("C");
- switcher = true;
- }
- }
- }
- }
- package Suarez;
- import java.io.*;
- import java.nio.file.InvalidPathException;
- import java.util.*;
- public class printData {
- public static void main(String[] args) throws IOException{
- try {
- Scanner file26 = new Scanner(new File("C:\\Users\\Arush\\IdeaProjects\\9th Grade Tri2\\src\\Suarez\\data2"));
- //Answer to problem 26
- for (int i = 0; i < 2; i++) {
- System.out.println(file26.nextLine());
- }
- }
- catch(IOException ioe){
- System.out.println(ioe.getMessage());
- }
- //Answer to problem 27
- try{
- Scanner file27 = new Scanner(new File("C:\\Users\\Arush\\IdeaProjects\\9th Grade Tri2\\src\\Suarez\\data2"));
- int i = 0;
- while(file27.hasNextLine()) {
- i++;
- }
- String [] fileArray = new String [i];
- String temp = "";
- String convert = "";
- for(int k = 0; k < fileArray.length; k++){
- convert = file27.nextLine();
- fileArray[k] = convert;
- }
- for(int f = 0; f < fileArray.length-1; f++) {
- for(int j = 0; j < fileArray.length-1; j++) {
- if (fileArray[j].compareTo(fileArray[j + 1]) < 0) {
- temp = fileArray[j];
- fileArray[j] = fileArray[j + 1];
- fileArray[j + 1] = temp;
- }
- }
- }
- for(int n = 0; n < fileArray.length; n++) {
- System.out.print(fileArray[n] + " ");
- }
- }
- catch(InvalidPathException ipe){
- System.out.println(ipe.getMessage());
- }
- catch(IOException ioe){
- System.out.println(ioe.getMessage());
- }
- catch(SecurityException se){
- System.out.println(se.getMessage());
- }
- //Answer to problem 28
- try
- {
- Scanner file28 = new Scanner(new File("C:\\Users\\Arush\\IdeaProjects\\9th Grade Tri2\\src\\Suarez\\data2"));
- String result = "";
- while(file28.hasNextLine()) {
- result += file28.nextLine() + " ";
- }
- System.out.println(result);
- }
- catch (IOException ioe) {
- ioe.printStackTrace();
- }
- //Answer to problem 29
- try
- {
- Scanner file29 = new Scanner(new File("C:\\Users\\Arush\\IdeaProjects\\9th Grade Tri2\\src\\Suarez\\data2"));
- String result = "";
- while(file29.hasNextLine()) {
- String line = file29.nextLine();
- if(line.length() >= 2) {
- if (line.substring(0,2).equalsIgnoreCase("sp")) {
- result += line + " ";
- }
- }
- }
- System.out.println(result);
- file29.close();
- }
- catch (IOException ioe) {
- ioe.printStackTrace();
- }
- }
- }
- data2.txt
- Java
- Illuminated
- Programming
- Is Not A
- Spectator
- Sport
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement