Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 2, Problem 12RE
Find three run-time errors in the following
public class HasErrors
{
public static void main(String[] args)
{
int x = 0;
int y = 0;
Scanner in = new Scanner(“System.in”);
System.out.print(“Please enter an integer: ”);
x = in.readInt();
System.out.print(“Please enter another integer: ”);
x = in.readInt();
System.out.println(“The sum is ” + x + y);
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Complete this program to print a table of prices. The first column has width 8 and the second column has width 10. Print the prices with two digits after the decimal point.
import java.util.Scanner;
public class Table{public static void main(String[] args){Scanner in = new Scanner(System.in);System.out.print("Unit price: ");double price = in.nextDouble();
System.out.println("Quantity Price");int quantity = 1;
System.out.printf("%8d%n",quantity, (quantity * price) );quantity = 12;System.out.printf("%8d%n",quantity, (quantity * price));quantity = 100;System.out.printf("%8d%n",quantity, quantity * price);
Select the correct output for the below program
public class thisClass
{
public static void main(String[] args)
{ for (int count= 0; count <11; count++)
{
if(count%2==0)
System.out.print(" "+count);
else
System.out.print(" "+@);
}
}
}
A) 1 2 3 4 5 6 7 8 9 10
B) 1 3 5 7 9
C) 2 4 6 8 10
D) Error
Explain the purpose of everyline of this program.
Source Code:
import java.util.Scanner;
public class MinutesConversion {
public static void main(String args[]){ Scanner input = new Scanner(System.in); System.out.print("Enter the hours to convert:"); int minites =input.nextInt(); double hours=convertToHours(minites); double days=convertToDays(minites); System.out.println(minites+" minutes equals "+hours+" hours and equals "+days+" days"); } public static double convertToHours(int minites){ double hours=(double)minites/60.00; return hours; }
public static double convertToDays(int minites){ double days=(double)minites/(60.00*24); return days; }}
Chapter 2 Solutions
Big Java Late Objects
Ch. 2.1 - Declare a variable suitable for holding the number...Ch. 2.1 - What is wrong with the following variable...Ch. 2.1 - Declare and initialize two variables, unitPrice...Ch. 2.1 - Prob. 4SCCh. 2.1 - Some drinks are sold in four-packs instead of...Ch. 2.1 - Prob. 6SCCh. 2.1 - Prob. 7SCCh. 2.1 - Prob. 8SCCh. 2.1 - How would you explain assignment using the parking...Ch. 2.2 - A bank account earns interest once per year. In...
Ch. 2.2 - In Java, how do you compute the side length of a...Ch. 2.2 - The volume of a sphere is given by V=43r3 If the...Ch. 2.2 - Prob. 13SCCh. 2.2 - Prob. 14SCCh. 2.3 - Write statements to prompt for and read the users...Ch. 2.3 - What is wrong with the following statement...Ch. 2.3 - Prob. 17SCCh. 2.3 - What is problematic about the following statement...Ch. 2.3 - What is the output of the following statement...Ch. 2.3 - Using the printf method, print the values of the...Ch. 2.4 - Prob. 21SCCh. 2.4 - Suppose the architect specifies a pattern with...Ch. 2.4 - A robot needs to tile a floor with alternating...Ch. 2.4 - For a particular car, repair and maintenance costs...Ch. 2.4 - The shape of a bottle is approximated by two...Ch. 2.5 - What is the length of the string "Java Program"?Ch. 2.5 - Consider this string variable. String str = "Java...Ch. 2.5 - Use string concatenation to turn the string...Ch. 2.5 - Prob. 29SCCh. 2.5 - Prob. 30SCCh. 2 - Write declarations for storing the following...Ch. 2 - What is the value of mystery after this sequence...Ch. 2 - What is wrong with the following sequence of...Ch. 2 - Write the following mathematical expressions in...Ch. 2 - Write the following Java expressions in...Ch. 2 - What are the values of the following expressions?...Ch. 2 - What are the values of the following expressions,...Ch. 2 - What are the values of the following expressions?...Ch. 2 - Assuming that a and b are variables of type int,...Ch. 2 - Suppose direction is an integer angle between 0...Ch. 2 - Find at least five compile-time errors in the...Ch. 2 - Find three run-time errors in the following...Ch. 2 - Consider the following code segment. double...Ch. 2 - Explain the differences between 2, 2.0, 2, 2, and...Ch. 2 - Explain what each of the following program...Ch. 2 - Write pseudocode for a program that reads a word...Ch. 2 - Write pseudocode for a program that reads a name...Ch. 2 - Write pseudocode for a program that computes the...Ch. 2 - Modify the pseudocode for the program in How To...Ch. 2 - Prob. 20RECh. 2 - You are cutting off a piece of pie like this,...Ch. 2 - The following pseudocode describes how to obtain...Ch. 2 - Suppose you are given a string str and two...Ch. 2 - Prob. 24RECh. 2 - For each of the following computations in Java,...Ch. 2 - Prob. 26RECh. 2 - This chapter contains a number of recommendations...Ch. 2 - Write a program that displays the dimensions of a...Ch. 2 - Write a program that computes and displays the...Ch. 2 - Write a program that reads a number and displays...Ch. 2 - Write a program that prompts the user for two...Ch. 2 - Enhance the output of Exercise E2.4 so that the...Ch. 2 - Write a program that prompts the user for a...Ch. 2 - Write a program that prompts the user for a radius...Ch. 2 - Write a program that asks the user for the lengths...Ch. 2 - Improve the program discussed in How To 2.1 to...Ch. 2 - Write a program that helps a person decide whether...Ch. 2 - Write a program that asks the user to input The...Ch. 2 - File names and extensions. Write a program that...Ch. 2 - Write a program that reads a number between 1,000...Ch. 2 - Write a program that reads a number between 1,000...Ch. 2 - Printing a grid. Write a program that prints the...Ch. 2 - Write a program that reads in an integer and...Ch. 2 - Write a program that reads two times in military...Ch. 2 - Writing large letters. A large letter H can be...Ch. 2 - Write a program that transforms numbers 1, 2, 3, ,...Ch. 2 - Write a program that prints a Christmas tree:...Ch. 2 - Easter Sunday is the first Sunday after the first...Ch. 2 - In this project, you will perform calculations...Ch. 2 - The following pseudocode describes how a bookstore...Ch. 2 - The following pseudocode describes how to turn a...Ch. 2 - The following pseudocode describes how to extract...Ch. 2 - Giving change. Implement a program that directs a...Ch. 2 - An online bank wants you to create a program that...Ch. 2 - A video club wants to reward its best members with...Ch. 2 - Consider the following circuit. Write a program...Ch. 2 - The dew point temperature Td can be calculated...Ch. 2 - The pipe clip temperature sensors shown here are...Ch. 2 - Prob. 12PPCh. 2 - Consider the following tuning circuit connected to...Ch. 2 - According to the Coulomb force law, the electric...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Give a recursive algorithm to compute the product of two positive integers, m and n, using only addition and su...
Data Structures and Algorithms in Java
Rewrite the temperature conversion program of Section 1.2 to use a function for conversion.
C Programming Language
If you use a variable in a function definition, where should you declare the variable? In the function definiti...
Problem Solving with C++ (10th Edition)
Let us examine the rationality of various vacuum-cleaner agent functions. a. Show that the simple vacuum-cleane...
Artificial Intelligence: A Modern Approach
Explain what must be done when fully replicating a database but allowing only one computer to process updates.
Database Concepts (7th Edition)
By default, are the members of a structure public or private? _____________
Starting Out with C++: Early Objects (9th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Convert this Java Program below into simplest form. It should still produce the same result as indicated in the picture. CODES: import java.util.Scanner public class Main { public static void main(String[] arg){ //declaration String lname, fname, dtype, ltype; int dcode, lcode; double lfee, dfee, tfee; //assigning data dtype = "Special"; ltype="Citywide"; dfee=30.50; //input System.out.printf("\n"); Scanner in = new Scanner(System.in); System.out.printf("Lastname of Sender: "); lname = in.nextLine(); System.out.printf("Firstname of Sender: "); fname = in.nextLine(); System.out.printf("Deliver Code: "); dcode = in.nextInt(); System.out.printf("Letter Fee: "); lfee = in.nextFloat(); //compute tfee = lfee + dfee; //display System.out.printf("\n\n\n"); System.out.printf("Sender Name: %s %s \n", fname, lname); System.out.printf("Delivery Name: %d \n", dcode); System.out.printf("Delivery Type: %s \n", dtype);…arrow_forwardimport java.util.*;public class TestAverage {public static void main(String[] args) {int test1, test2, test3, sum;Scanner reader = new Scanner(System.in);System.out.println("Enter test 1");test1 = reader.nextInt();System.out.println("Enter test 2");test2 = reader.nextInt();System.out.println("Enter test 3");test3 = reader.nextInt();sum = test1 + test2 + test3;System.out.println("The sum is " + sum);System.out.println("The average is " + sum / 3);}}a. Briefly explain what this code does.b. There is one logic error in this code explain what is wrong and how to fix it.arrow_forwardI need help with this Java Problem as described in the image below: import java.util.Scanner; public class LabProgram { public static int fibonacci(int n) { /* Type your code here. */ } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int startNum; startNum = scnr.nextInt(); System.out.println("fibonacci(" + startNum + ") is " + fibonacci(startNum)); }}arrow_forward
- import java.util.Scanner; public class DebugSix4 { public static void main(String[] args) { int high, low, count = 0; final int NUM = 5; Scanner input = new Scanner(System.in); System.out.print("This application displays " + NUM + " random numbers" + "\nbetween the low and high values you enter" + "\nEnter low value now... "); low = input.nextInt(); // Inserted the missing semicolon System.out.print("Enter high value... "); high = input.nextInt(); // Added the missing dot to the method call. while (low >= high) { // For proper input validation, changed "" to ">=" System.out.println("The number you entered for a high number, " + high + ", is not more than " + low); System.out.print("Enter a number higher than " + low + "... "); high =…arrow_forwardThis is a debugging problem I am stuck on - The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. This is the code - import java.util.*; public class DebugNine2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); Movie[] movies = new Movie[8]; int i; String message, entry; movies[0] = new Movie("The Godfather", 1972); movies[0] = new Movie("The Good, the Bad, and the Ugly", 1966); movies[0] = new Movie("Pulp Fiction", 1994); movies[0] = new Movie("Shindler's List", 1993); movies[4] = new Movie("Casablanca", 1942); movies[5] = new Movie("Wizard of Oz", 1939); movies[6] = new Movie("Citizen Kane", 1941); movies[7] = new Movie("Some Like It Hot", 1959); System.out.println( "Sort Movies by\n(N)ame, or (Y)ear");…arrow_forwardJAVA Program modify this program below: take out while (true) { and use something else. Instead it uses recursive method that doesn't copy the string over and over again. import java.util.Scanner;public class PalindromeChecker { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { System.out.print("Please enter a string to test for palindrome or type QUIT to exit:\n"); String input = scanner.nextLine().toLowerCase(); if (input.equals("quit")) { break; } if (isPalindrome(input)) { System.out.println("The input is a palindrome."); } else { System.out.println("The input is not a palindrome."); } } } private static boolean isPalindrome(String str) { str = str.replaceAll("[^a-zA-Z0-9]", ""); int left = 0; int right = str.length() - 1; while (left < right) {…arrow_forward
- A java program that accepts ingredients for a recipe in cups and converts to ounces. The coding is: import java.util.Scanner; public class Chpt4_Project { public static int totalOunce(int n) { int num_ounce = 8*n; return num_ounce; } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter first ingredient: "); String ingred1 = input.nextLine(); System.out.print("Enter second ingredient: "); String ingred2 = input.nextLine(); System.out.print("Enter third ingredient: "); String ingred3 = input.nextLine(); System.out.print("Enter number of cups for the first ingredient: "); int number1 = input.nextInt(); System.out.print("Enter number of cups for the second ingredient: "); int number2 = input.nextInt(); System.out.print("Enter number of cups for the third ingredient: "); int number3 = input.nextInt(); int totalCups = number1 + number2 + number3; System.out.println("The recipe uses " + ingred1+", "+ingred2+", "+ingred3 );…arrow_forwardSo this is my code but it give me error where did i do wrong? import java.util.Scanner;public class equationy {public static void main(String args[]){Scanner input=new Scanner(System.in);int m,x,c,y;System.out.println("Enter m");m=input.nextInt();System.out.println("Enter x");x=input.nextInt();System.out.println("Enter c");c=input.nextInt();y=m*x+c;System.out.printf("y = %d" , y);}}arrow_forwardGetting a error message and I dont understand why public class DebugTwo2 { public static void main(String args[]) { { int a, b; a = 7; b = 4; System.out.println("The sum is " + (a + b); System.out.println("The difference is " + (a - b); System.out.println("The product is " + (a * b); }arrow_forward
- Identify the errors in the following program. 2 errorspublic class Test {public static void main(String[] args) {nPrintln(5, "Welcome to Java!");}public static void nPrintln(String message, int n) {for (int i = 0; i < n; i++) {System.out.println(message);}return n;}}arrow_forwardFix the code so it runs. Take note of what errors are generated by the compiler. What do these errors mean? How do they help you find and fix the errors? import java.util.Scanner; public class Main {public static void main(String[] args) { int numOfBooks = 130;char bookStoreAns; do {System.out.println("Are you at the book store? (y/n)");bookStoreAns = scnr.next().charAt(0);boolean atBookStore; if (bookStoreAns == 'y') {atBookStore = true;} else if (bookStoreAns == 'n') {atBookStore = false;}} while (bookStoreAns != 'y' && bookStoreAns != 'n'); if (atBookStore) {numOfBooks += 4;} System.out.println("I have " + numOfBooks + " books."); }} Can anyone fix this code in Java?arrow_forwardModify this JAVA Program Take out while (true) { from the program and use something else. Instead use a recursive method that doesn't copy the string over and over again. import java.util.Scanner;public class PalindromeChecker { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { System.out.print("Please enter a string to test for palindrome or type QUIT to exit:\n"); String input = scanner.nextLine().toLowerCase(); if (input.equals("quit")) { break; } if (isPalindrome(input)) { System.out.println("The input is a palindrome."); } else { System.out.println("The input is not a palindrome."); } } } private static boolean isPalindrome(String str) { str = str.replaceAll("[^a-zA-Z0-9]", ""); int left = 0; int right = str.length() - 1; while (left < right) {…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY