Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. In the following code, what values could be read into number to terminate the while loop? } a. Numbers less than 100 or
1. In the following code, what values could be read into number to terminate the while loop? } a. Numbers less than 100 or greater than 500 b. Numbers in the range 100 - 499 c. Numbers in the range 100 - 500 d. The boolean condition can never be true 2. Given the following statement, which statement will write "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt"); System.out.println(diskOut, "Calvin"); Scanner keyboard = new Scanner(System.in); System.out.print("Enter a number: "); int number = keyboard.nextInt(); while (number < 100 || number > 500) { a. b. DiskFile.println("Calvin"); C. PrintWriter.println("Calvin"); diskOut.println("Calvin"); d. a. System.out.print("Enter another number: "); number = keyboard.nextInt(); 3. Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops shows the correct way to read data from the file until the end of the file is reached? while (inputFile != null) b. (...) C. (...) d. (...) while (!inputFile.EOF) while (inputFile.hasNext()) while (inputFile.nextLine == "") 4. Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file? a. int number = inputFile.next(); b. int number = inputFile.integer(); int number = inputFile.readint(); C. d. int number = inputFile.nextInt(); 5. Which of the following statements opens a file named MyFile.txt and allows you to read data from it? a. Scanner inputFile = new Scanner("MyFile.txt"); b. File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file); c. File Scanner = new File("MyFile.txt"); d. PrintWriter inputFile = new PrintWriter("MyFile.txt");
Step by Step Solution
★★★★★
3.30 Rating (150 Votes )
There are 3 Steps involved in it
Step: 1
Answer 1 c Numbers in the range 100 500 2 d diskOutprintlnCalvin 3 c while inputFilehasNext 4 d int number inputFilenextInt 5 b File file new FileMyFiletxt Scanner inputFile new Scannerfile Explanatio...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