Question
The following code needs completing , method getToken() Increment k by 1 if k IS LESS THAN the length of expr Assign to token the
The following code needs completing , method getToken() Increment k by 1 if k IS LESS THAN the length of expr Assign to token the kth character of expr Put token to output file end if end method getToken
input-1.tx: 2-3
2*4*5
(1+2)*5
Given:
public class Main { static char token; static String expr; static int k = 0;
public static void main(String[] args)throws Exception{ Scanner scanner = new Scanner(new java.io.File("input-1.txt")); FileWriter myWriter = new FileWriter("output.txt");
//Read from the file while(scanner.hasNext()) { expr=scanner.nextLine();
}
} char getToken() { if(k < expr.length()) { token = expr.charAt(k); } }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started