Added Read file and the source code inputs.
This commit is contained in:
parent
4bede63054
commit
50727f38f4
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
7
src/edu/jt_kb/cs4308/compiler/resources/Java.txt
Normal file
7
src/edu/jt_kb/cs4308/compiler/resources/Java.txt
Normal 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);
|
||||
}
|
||||
}
|
3
src/edu/jt_kb/cs4308/compiler/resources/Python.txt
Normal file
3
src/edu/jt_kb/cs4308/compiler/resources/Python.txt
Normal file
@ -0,0 +1,3 @@
|
||||
def add_numbers(num1, num2):
|
||||
sum = num1 + num2
|
||||
print('Sum: ',sum)
|
Reference in New Issue
Block a user