Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 13.3, Problem 13.3.4CP
What is wrong in the following code? (Note the compareTo method for the Integer and Double classes was introduced in Section 10.7.)
public class Test {
public static void main(String[] args) {
Number x = new Integer(3);
System.out.println(x.intValue());
System.out.println(x.compareTo(new Integer(4)));
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
java
Method Overloading is a feature that allows a class to have two or more methods having
same name, if their argument lists are different. Argument lists could differ in:
1. Number of parameters.
2. Data type of parameters.
3. Sequence of Data type of parameters.
Write different version of method sum() that display the sum of the values received as
parameter according to the following main method content:
public static void main(String[] args)
{
sum ( 10, 10 );
sum ( 10, 10, 10 );
sum ( 10.0, 10.0 );
sum ( 10, 10.0 );
sum ( 10.0, 10);
}
You have to define five functions with the specified types. Then, demonstrate the Argument
Promotion concept by reducing the number of method to two.
10.
public static void methodl (int i, int num) {
for (int j = 1; j <= i; j++) {
" ");
System.out.print (num +
num *= 2;
}
System.out.println();
}
public static void main(String[] args) {
int i = 1;
while (i <= 6) {
methodl (i, 2);
i++;
}
Chapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 13.2 - Prob. 13.2.1CPCh. 13.2 - The getArea() and getPerimeter() methods may be...Ch. 13.2 - True or false? a.An abstract class can be used...Ch. 13.3 - Prob. 13.3.1CPCh. 13.3 - Prob. 13.3.2CPCh. 13.3 - Prob. 13.3.3CPCh. 13.3 - What is wrong in the following code? (Note the...Ch. 13.3 - What is wrong in the following code? public class...Ch. 13.4 - Can you create a Calendar object using the...Ch. 13.4 - Prob. 13.4.2CP
Ch. 13.4 - How do you create a Calendar object for the...Ch. 13.4 - For a Calendar object c, how do you get its year,...Ch. 13.5 - Prob. 13.5.1CPCh. 13.5 - Prob. 13.5.2CPCh. 13.5 - Prob. 13.5.3CPCh. 13.5 - Prob. 13.5.4CPCh. 13.6 - Prob. 13.6.1CPCh. 13.6 - Prob. 13.6.2CPCh. 13.6 - Can the following code be compiled? Why? Integer...Ch. 13.6 - Prob. 13.6.4CPCh. 13.6 - What is wrong in the following code? public class...Ch. 13.6 - Prob. 13.6.6CPCh. 13.6 - Listing 13.5 has an error. If you add list.add...Ch. 13.7 - Can a class invoke the super.clone() when...Ch. 13.7 - Prob. 13.7.2CPCh. 13.7 - Show the output of the following code:...Ch. 13.7 - Prob. 13.7.4CPCh. 13.7 - What is wrong in the following code? public class...Ch. 13.7 - Show the output of the following code: public...Ch. 13.8 - Prob. 13.8.1CPCh. 13.8 - Prob. 13.8.2CPCh. 13.8 - Prob. 13.8.3CPCh. 13.9 - Show the output of the following code: Rational r1...Ch. 13.9 - Prob. 13.9.2CPCh. 13.9 - Prob. 13.9.3CPCh. 13.9 - Simplify the code in lines 8285 in Listing 13.13...Ch. 13.9 - Prob. 13.9.5CPCh. 13.9 - The preceding question shows a bug in the toString...Ch. 13.10 - Describe class-design guidelines.Ch. 13 - (Triangle class) Design a new Triangle class that...Ch. 13 - (Shuffle ArrayList) Write the following method...Ch. 13 - (Sort ArrayList) Write the following method that...Ch. 13 - (Display calendars) Rewrite the PrintCalendar...Ch. 13 - (Enable GeometricObject comparable) Modify the...Ch. 13 - Prob. 13.6PECh. 13 - (The Colorable interface) Design an interface...Ch. 13 - (Revise the MyStack class) Rewrite the MyStack...Ch. 13 - Prob. 13.9PECh. 13 - Prob. 13.10PECh. 13 - (The Octagon class) Write a class named Octagon...Ch. 13 - Prob. 13.12PECh. 13 - Prob. 13.13PECh. 13 - (Demonstrate the benefits of encapsulation)...Ch. 13 - Prob. 13.15PECh. 13 - (Math: The Complex class) A complex number is a...Ch. 13 - (Use the Rational class) Write a program that...Ch. 13 - (Convert decimals to fractious) Write a program...Ch. 13 - (Algebra: solve quadratic equations) Rewrite...Ch. 13 - (Algebra: vertex form equations) The equation of a...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
List the specific functions of a DBMS.
Database Concepts (8th Edition)
Determine the output, X, for a 2-input AND gate with the input waveforms shown in Figure 3-78. Show the proper ...
Digital Fundamentals (11th Edition)
Consider a class characteristic that will be used in an online dating service to assess how compatible two peop...
Java: An Introduction to Problem Solving and Programming (7th Edition)
What type of error usually causes the program to abruptly halt?
Starting Out With Visual Basic (8th Edition)
Write a program to count blanks, tabs and newlines.
C Programming Language
Write a while loop that lets the user enter a number. The number should be multiplied by 10, and the result ass...
Starting Out with Python (3rd 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
- The following class definition has errors. Explain what is wrong and why. Rewrite a correct version of the class. class Question2( public static main(String[] args){ int num1 = 10, num2 = 20, num3; (num2 / 2)--; num3 = (num1 + num2)/num3 System.out.printin( num3 );arrow_forwardComplete the convert() method that casts the parameter from a double to an integer and returns the result.Note that the main() method prints out the returned value of the convert() method. Ex: If the double value is 19.9, then the output is: 19 Ex: If the double value is 3.1, then the output is: 3 code: public class LabProgram { public static int convert(double d){ /* Type your code here */ } public static void main(String[] args) { System.out.println(convert(19.9)); System.out.println(convert(3.1)); }}arrow_forwardJava- Consider this method declaration: void quiz(int i) { if (i > 1) { quiz(i/2); quiz(i/2); } system.out.print(“*”); } How many asterisks are printed by the method call quiz(4) ?arrow_forward
- Apex(Salesforce) Write the Apex Test Class for the Below Apex Method and also show the code Coverage Output Here is the Apex code: - public with sharing class MyFirstClass { public static Integer performMultiplication(Integer int1, Integer int2) { //Create a variable for checking null values Integer int3=1; //Check if both the integer not null or have some value in it if(int1!=null && int2!=null) { int3 = int1*int2; } else if (int1==null && int2!=null) { int3 = int2; } else if(int1!=null && int2==null) { int3=int1; } return int3; }}arrow_forward1- public class Con{ public static void main(String[] args) int[] ar=(2,5,7,9}; int i=2; final int j=1; 6. for (int x:ar) 8- { 9 if(ar[i]arrow_forwardJava Question - Please see attached picture. Thanks.arrow_forward/ Java program to demonstrate how // to use gcd method of BigInteger class import java.math.BigInteger; class Test { public static int gcd(int a, int b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.intValue(); } public static long gcd(long a, long b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.longValue(); } // Driver method public static void main(String[] args) {.arrow_forwardIdentify the error(s) in the program and describe why this error occurs. Rewrite the code after correcting all errors. package Overview interface MyInt{ int a; void seta(int alpha); } public class CheckTest implements MyInt { @Override public void seta(int alpha) {a = alpha;} public static void main(String[] args) { seta(5); } }arrow_forwardQUESTION 4 Analyze the following code: public class Test { public static void main (String [] args) { int i = 0; while (i ++ < 10); System.out.println(i + 4); The program compiles despite the semicolon () on the for loop line, and displays 15. The program has a compile error because of the semicolon (;) on the while loop line. The program compiles despite the semicolon (:) on the while loop line, and displays 4.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_forwardCorrect the error in this method: public void getAge() { return age; }arrow_forwardClass Utilities { Method Details addDelimiter: public static java.lang.String addDelimiter(java.lang.String str, char delimeter) Returns a string where characters are separated by the specified delimeter character. A string with a single character will not have a delimeter added. The space character is consider a character (similar to character 'A'). You can assume str will never be the empty string. You may not use an auxiliary method in order to implement this method. Your implementation must be recursive and you may not use any loop construct. Note: In java given two characters a and b, a + b will not create a string. To create a string, append a to the empty string and the result to b. From the String class, the only methods you can use are length(), isEmpty(), charAt() and substring. Do not use ++ or -- in any recursive call argument. It may lead to an infinite recursion. For example, use index + 1, instead of index++. Parameters: str - delimeter - Returns: String with characters…arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_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
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License