B.Sc. (H) Computer Science, Semester II Lab Exercises
BHCS03 – Programming in JAVA
Attempt the following questions as part of JAVA Lab class today:
1. Write a method printIntegers() that reads integer values from a file and prints them to standard output. For those lines of the file that do not contain an integer value (e.g., they contain alphabetic characters) the program should print the string
"***" and continue reading from the file.
2. Write a class containing the following static methods:
a. fileExists(), that takes as a parameter a string and returns a boolean value that is true, if the file whose name is passed as parameter exists, and false otherwise;
b. isInt(), that takes as parameter a string and returns a boolean value that is true if the string represents an integer, and false otherwise.
c. isDouble(), that takes as parameter a string and returns a boolean value that is true if the string represents a real number, and false otherwise.
Solve the exercises by suitably catching exceptions.
PS: You may send the solutions and/or doubts to
[email protected]. The file that you send should be saved with your roll number-subject name-today’s date.