Reset author name to chosen name ✨
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
*/
|
||||
|
||||
package com.chloefontenot.lab7_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Lab7_ChloeFontenot {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.lab7_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class OOM {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try {
|
||||
Integer[][] oomArray = new Integer[20000][20000];
|
||||
for (int i = 0; i < oomArray.length; ++i ) {
|
||||
for (int j = 0; j < oomArray.length; ++j ) {
|
||||
oomArray[i][j] = i * j;
|
||||
//System.out.println(oomArray[i][j]);
|
||||
}
|
||||
}
|
||||
} catch (OutOfMemoryError ex) {
|
||||
System.out.println("Out of memory! " + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.lab7_chloefontenot;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class occurrencesOfEachCharacter {
|
||||
public static void main(String[] args) {
|
||||
System.out.println((int) 'a' + ", " + (int) 'z');
|
||||
// Number array for each letter in alphabet
|
||||
int[] letterCount = new int[26];
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter a path to a file to scan: ");
|
||||
File filePath = new File(input.nextLine());
|
||||
try (Scanner fileScanner = new Scanner(filePath);) {
|
||||
char currentChar;
|
||||
int arrayIndex = 0;
|
||||
//Instruct scanner to delimit at everything
|
||||
fileScanner.useDelimiter("");
|
||||
while (fileScanner.hasNext()) {
|
||||
currentChar = fileScanner.next().toLowerCase().charAt(0);
|
||||
arrayIndex = ((int) currentChar - 97); //This will determine where in the array to increment at
|
||||
//System.out.println(currentChar);
|
||||
if (currentChar > 'a' & currentChar < 'z') {
|
||||
letterCount[arrayIndex]++;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
System.out.println(ex);
|
||||
}
|
||||
//Alright. We should have an array with a count of every char in the file.
|
||||
for (int i = 0; i < letterCount.length; ++i) {
|
||||
if (letterCount[i] > 0) {
|
||||
System.out.println("Number of " + Character.toUpperCase((char) (i + 97)) + "'s: " + letterCount[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.chloefontenot.lab7_chloefontenot;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class removeAllOccurances {
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException, IOException {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter a path to a file: ");
|
||||
String sourcePath = input.nextLine();
|
||||
System.out.print("Replace what with what? (ex. If you want to replace John with Mary, type: \'John Mary\'): ");
|
||||
String source = input.next();
|
||||
String target = input.next();
|
||||
input.nextLine(); // Consume newline left-over
|
||||
System.out.print("Enter the output file path: ");
|
||||
String destinationPath = input.nextLine();
|
||||
|
||||
File sourceFile = new File(sourcePath);
|
||||
File destinationFile = new File(destinationPath);
|
||||
String[] fileContents = new String[(int) countLines(sourceFile)];
|
||||
try (Scanner sourceScanner = new Scanner(sourceFile)) {
|
||||
for (int i = 0; i < countLines(sourceFile); ++i) {
|
||||
fileContents[i] = sourceScanner.nextLine();
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < fileContents.length; ++i) {
|
||||
fileContents[i] = fileContents[i].replace(source, target);
|
||||
System.out.println(fileContents[i]);
|
||||
}
|
||||
// Write contents to new file
|
||||
try (PrintWriter fw = new PrintWriter(destinationFile);) {
|
||||
for (int i = 0; i < fileContents.length; ++i) {
|
||||
fw.println(fileContents[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int countLines(File sourceFile) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(sourceFile));
|
||||
int lines = 0;
|
||||
while (reader.readLine() != null) {
|
||||
lines++;
|
||||
}
|
||||
reader.close();
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user