Question: 1) Write a a program named result that takes the three arguments. The first argument is a single character, one of: +, -, x. The
1) Write a a program named result that takes the three arguments. The first argument is a single character, one of: +, -, x. The next two are integers. Your program should output to standard out the result of applying the operator in the first argument, to the two integers in the second and third.
2) Extend the program above to also be able to handle the operator / (division) as the first parameter.
3)Write a new program called resultfile, that performs the same operation as question 4, but instead of reading arguments from the command line, it reads from standard input.
4)When reading from standard in, the OS lets your program know it has reached the end of file by sending an EOF character. When typing manual input to a program in UNIX in the command line, you can manually send an EOF character (signalling youre done sending input to the program) by typing CTRL-D. From within Java you can use the class Scanner, to perform input and check for end of file.
For example, what does the next snippet of code do? Scanner s = new Scanner(System.in); while (s.hasNextInt()) { an_array[i] = s.nextInt(); i++; } while (i >= 0) { System.out.println(an_array[i]); i-; } Write a program that uses the above snippet, and verify your answer.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
