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
// Displays five random numbers between
// (and including) user-specified values
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()
System.out.print("Enter high value... ");
high = inputnextInt();
while(low < high)
{
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 = input.nextInt();
while(count < NUM)
{
double result = Math.random();
int answer = (int) (result * 10 + low);
if(answer <=…
Input
class Output
{
public static void main(String args[])
{
int x , y = 1;
x = 10;
if (x != 10 && x / 0 == 0)
System.out.println(y);
else
System.out.println(++y);
}
}
Find output
class Output{public static void main(String args[]){Integer i = new Integer(557);float x = i.floatValue();System.out.print(x);}}
What will the given code prints on the output screen.
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
- // ArtShow.java - This program determines if an art show attendee gets a 5% discount // for preregistering. // Input: Interactive. // Output: A statement telling the user if they get a discount or no discount. import java.util.Scanner; public class ArtShow { public static void main(String args[]) { Scanner s = new Scanner(System.in); String registerString; System.out.println("Did you preregister? Enter Y or N: "); registerString = s.nextLine(); // Test input here. If Y, call discount(), else call noDiscount(). System.exit(0); } // End of main() method. // Write discount method here. // Write noDiscount method here. } // End of ArtShow class.arrow_forward// DebugFive4.java // Outputs highest of four numbers import java.util.*; public class DebugFive4 { publicstaticvoidmain (Stringargs[]) { Scanner input =newScanner(System.in); int one, two, three, four; String str, output; System.out.println("Enter an integer"); str = input.next(); one = Integer.parseInt(str); System.out.println("Enter an integer"); str = input.next(); two = Integer.parseInt(str); System.out.println("Enter an integer"); str = input.next(); three = Integer.parseInt(str); System.out.println("Enter an integer"); str = input.next(); four = Integer.parseInt(str); if(one > two > one > three > one > four) output = "Highest is " + four; else if(two > one && two > three !! two > four) output = "Highest is " + three; else if(three > one && three > two && three > four) output = "Highest is " + three; else output = "Highest is " + four; System.out.println(output); } }arrow_forward// DebugFive2.java // Decides if two numbers are evenly divisible import java.util.Scanner; public class DebugFive2 { publicstaticvoidmain(Stringargs[]) { int num; int num2; Scanner input =newScanner(System.in); System.out.print("Enter a number "); num = input.nextInteger() System.out.print("Enter another number "); num2 = inputnextInt(); if((num % num2 ==0) && (num2 % num) ==0) System.out.println("One of these numbers is evenly divisible into the other"); else System.out.println("Neither of these numbers is evenly divisible into the other"); } }arrow_forward
- import java.util.Scanner;/** This program calculates the geometric and harmonic progression for a number entered by the user.*/public class Progression{ public static void main(String[] args) { Scanner keyboard = new Scanner (System.in); System.out.println("This program will calculate " + "the geometric and harmonic " + "progression for the number " + "you enter."); System.out.print("Enter an integer that is " + "greater than or equal to 1: "); int input = keyboard.nextInt(); // Match the method calls with the methods you write int geomAnswer = geometricRecursive(input); double harmAnswer = harmonicRecursive(input); System.out.println("Using recursion:"); System.out.println("The geometric progression of " + input + " is " + geomAnswer); System.out.println("The harmonic progression of " +…arrow_forwardExercise 3: The following code asks a user to enter her/his age then determines if a user is an adult or not. Trace the code, to find and solve the syntax errors. You need to identify the errors and rewrite the correct code. import java.util.Scanner; public class Ex3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println(("Enter your age:"); int age = input.nextInt(); double flag = isAdult(double age); if(flag) { System.out.println("You are an adult."); } else { System.out.println("You are not an adult."); } } public boolean isAdult(int age) { if(age > 18) { return true; } else { return false;arrow_forwardRemaining Time: 1 hour, 28 minutes, 35 seconds. * Question Completion Status: QUESTTON 11 There are five syntax errors in the following java program. Explain them by mentioning the line number with each error. public class public static void main (String [] args) { { double a = 9; 4 double b = 9.0; int x; System.out.println ("Sum of a and b is if( a = b) + (a+b)) 80 X = a; switch (a+b) { case 0: System.out.println (x); default: System.out.println (x) ; 10 11 12 13 14arrow_forward
- Print "userNum1 is negative." if userNum1 is less than 0. End with newline. Assign userNum2 with 4 if userNum2 is greater than 9. Otherwise, print "userNum2 is less than or equal to 9.". End with newline. 1 import java.util.Scanner; 2 public class UserNums { public static void main (String [] args) { int userNum1; int userNum2; 4 6. 7 Scanner input userNum1 = 8. = new Scanner(System.in); input.nextInt(); input.nextInt(); 9. 10 userNum2 11 12 V* Your code goes here */ 13 System.out.println("userNum2 is " } 14 + userNum2); 15 16 17 }arrow_forwardpublic class Test { } public static void main(String[] args){ int a = 10; System.out.println(a*a--); }arrow_forwardExamine this code and determine what happens when it is run: 1 public class Test { int x; 2 3 public Test(String t){ System.out.println("Test"); } public static void main(String[] args) { Test test = new Test ("boo"); System.out.println(test.x); } 4 5 6 7 8 10 } The program has a compile error because Test does not have a default constructor. The program has a compile error because System.out.println method cannot be invoked from the constructor. ) The program runs successfully and prints out: Test O The program has a compile error because you cannot create an object from the class that defines the object.arrow_forward
- public class Turn{public static void main(String[] args){// Different initial values will be used for testingint x = 1; int y = 1; // Turn the arrow by 90 degrees System.out.print("x:", y + 90);System.out.println(x);System.out.print("y: ", x - 1 );System.out.println(y); // Turn the arrow again System.out.print("x:", y - 1);System.out.println(x);System.out.print("y: ",x + 90);System.out.println(y);}}arrow_forward// Displays five random numbers between // (and including) user-specified values import java.util.Scanner; public class DebugSix4 { publicstaticvoidmain(String[] args) { int high, low, count =0; finalint NUM =5; Scanner input =newScanner(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() System.out.print("Enter high value... "); high = inputnextInt(); while(low < high) { 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 = input.nextInt(); while(count <NUM) { double result = Math.random(); int answer = (int) (result *10+ low); if(answer <= higher) { System.out.print(answer + " "); ++count; } } System.out.println("End of Application"); } }arrow_forwardFix all errors to make the code compile and complete. //MainValidatorA3 public class MainA3 { public static void main(String[] args) { System.out.println("Welcome to the Validation Tester application"); // Int Test System.out.println("Int Test"); ValidatorNumeric intValidator = new ValidatorNumeric("Enter an integer between -100 and 100: ", -100, 100); int num = intValidator.getIntWithinRange(); System.out.println("You entered: " + num + "\n"); // Double Test System.out.println("Double Test"); ValidatorNumeric doubleValidator = new ValidatorNumeric("Enter a double value: "); double dbl = doubleValidator.getDoubleWithinRange(); System.out.println("You entered: " + dbl + "\n"); // Required String Test System.out.println("Required String Test:"); ValidatorString stringValidator = new ValidatorString("Enter a required string: "); String requiredString =…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