Added Read file and the source code inputs.

This commit is contained in:
Jonathan Turner 2023-10-11 16:49:10 -04:00
parent 4bede63054
commit 50727f38f4
3 changed files with 41 additions and 0 deletions

View File

@ -1,7 +1,38 @@
package edu.jt_kb.cs4308.compiler;
import java.io.File;
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
System.out.println("Default Setup");
Driver program = new Driver();
program.start();
}
public void start() {
File java = new File("src/edu/jt_kb/cs4308/compiler/resources/Java.txt");
File python = new File("src/edu/jt_kb/cs4308/compiler/resources/Python.txt");
readFile(java);
System.out.println();
readFile(python);
}
private static void readFile(File file) {
try (Scanner input = new Scanner(file)) {
while (input.hasNextLine()) {
String line = input.nextLine();
char[] chars = line.toCharArray();
String result = "[";
for (char curr : chars) {
result += curr;
}
result += "]";
System.out.println(result);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,7 @@
public class JavaExample {
public static void main(String[] args) {
int num1 = 5, num2 = 15,sum;
sum = num1+num2;
System.out.println("Sum of "+num1+" and "+num2+" is: "+sum);
}
}

View File

@ -0,0 +1,3 @@
def add_numbers(num1, num2):
sum = num1 + num2
print('Sum: ',sum)