Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.*; class DebugNine1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String[][] books = new String[6][2]; books[0][0] = Ulysses; books[0][1]

import java.util.*; class DebugNine1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String[][] books = new String[6][2]; books[0][0] = "Ulysses"; books[0][1] = "James Joyce"; books[1][0] = "Lolita"; books[1][1] = "Vladimir Nabokov"; books[2][0] = "Huckleberry Finn"; books[2][1] = "Mark Twain"; books[3][0] = "Great Gatsby"; books[3][1] = "F. Scott Fitzgerald"; books[4][0] = "1984"; books[4][1] = "George Orwell"; books[5][0 ] = "Sound and the Fury"; books[5][1] = "William Faulkner"; String entry, shortEntry, message ="Enter the first three characters of a book title omitting \"A\" or \"The\" "; int x; boolean isFound = false; while(!isFound) { System.out.println(message); entry = input.next(); if(entry.length()<3){ System.out.println("Please input atleast 3 characters"); continue; } shortEntry = entry.substring(0,3); for(x = 0; x < books.length; ++x) if(books[x][0].startsWith(shortEntry)) { isFound = true; System.out.println(books[x][x] + " was written by: " + books[x][1]); x = books.length; } if(!isFound) System.out.println("Sorry - no such book in our database."); } input.close(); } } I am trying to figure out the logic and syntax errors in this code. I am getting the correct output for 1/3 of it. This is the error am I getting for 1: Vladimir Nabokov was written by: Vladimir Nabokov should say Lolita was written By Vlad.. 2: This is the error am getting for the last part. It should give me the output of 1984 was written by George Orwell. I don't understand why I am not getting the correct output.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

Students also viewed these Databases questions