I was trying java while i came across this problem, i dont get why my program is not printing anything in object array
import java.io.*;
import java.util.*;
class Symbol_Table{
String ST_1;
int LC_1;
};
public class week_1_3 {
static String in;
static int count=0, LC = 0,length =0;
static String arr[];
static String LT[] = new String[50];
static Symbol_Table ST[] = new Symbol_Table[50];
static int index =0;
public static void Two_or_less(/*String in, String arr[], int LC*/) {
if (arr[0] == "START" || arr[0] == "start") {
LC = Integer.parseInt(arr[1]);
LC += LC;
} else if (arr[0] == "END" || arr[0] == "end") {
return;
}
}
public static void Three(/*String in, String arr[], int LC,int index,String LT[],Symbol_Table ST[],int length*/) {
if (arr[2].substring(0, 1) == "=") {
LT[index] = arr[2];
index++;
LC++;
return;
} else if (arr[1] == "DC" || arr[1] == "DS") {
ST[length].ST_1 = arr[0];
ST[length].LC_1= LC;
length++;
LC = LC + Integer.parseInt(arr[2]);
} else {
LC++;
return;
}
}
public static void Four(/*String in,String arr[],int LC,int index,String LT[]*/){
if(arr[3].substring(0,1)=="="){
LT[index]= arr[3];
index++;
LC++;
return;
}
else{
LC++;
return;
}
}
public static void main(String[] args) {
try {
File file = new File("C:\\Users\\DELL\\Desktop\\Week_1.txt");
Scanner input = new Scanner(file);
while (input.hasNextLine()) {
in = input.nextLine();
in = in.replaceAll(",", " ");
count = in.split(" ").length;
arr = in.split(" ");
if (count <= 2) {
Two_or_less(/*in, arr, LC*/);
} else if (count == 3) {
Three(/*in, arr, LC,index,LT,ST,length*/);
}
else if(count==4){
Four(/*in,arr,LC,index,LT*/);
}
}
System.out.println("THE LITERAL TABLE :");
for(int i =0;i<index;i++){
System.out.println(LT[i]+" " +LC++);
}
System.out.println();
System.out.println("THE SYMBOL TABLE :");
for(int i =0;i<length;i++){
System.out.println(ST[i].ST_1+" "+ST[i].LC_1);
}
} catch (IOException ignored) {
System.out.println("File not found!!!");
}
}
}
can someone please lookup my error and guide me.
i want to print LT and ST (litral table and symbol table) while reading the text file
This code is for assembler basics.
error might be in main function to methods variable transition.