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 9.11, Problem 9.11.1CP
What is wrong in the following code?
1 public class Test {
2 public static void main(String [] args) {
3 java.util.Date[] dates = new java.util. Date[ 10];
4 System.out.println(dates[O]);
5 System.out.println(dates[O] .toString());
6 }
7 }
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Please help debug this: Debugging Exercise 4-3, Farrell, Joyce, Java Programming, 9th edition, Cengage Learning
public class DebugBox
{
private int width;
private int length;
private int height;
private FixDebugBox()
{
length = 1;
width = 1;
height = 1;
}
public DebugBox(int width, int length, int height)
{
width = width;
length = length;
height = height;
}
public void showData()
{
System.out.println("Width: " + width + " Length: " + length + " Height: " + height);
}
public double getVolume()
{
double vol = length - width - height;
return vol;
}
}
Manually trace the execution of the following Java code segment:
(c) if the following method is declared:
public static void drawLine(int num, char ch) {
for (int i = 1; i <= num; i++) {
System.out.print(ch);
}
}
What does the statement drawLine(10, ‘$’) do?
JAVA
Determine the output for the following code
public class Beta extends Baap
{
public int h = 44;
public int getH( )
{
System.out.println("Beta " + h);
return h;
}
public static void main(String[ ] args)
{
Baap b = new Beta();
System.out.println(b.h + " " + b.getH( ));
Beta bb = (Beta) b;
System.out.println(bb.h + " " + bb.getH( ));
}
}
public class Baap
{
public int h = 4;
public int getH( )
{
System.out.println("Baap " + h);
return h;
}
}
Chapter 9 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 9.3 - Prob. 9.3.1CPCh. 9.3 - How do you define a class?Ch. 9.3 - How do you declare an objects reference variable?Ch. 9.3 - How do you create an object?Ch. 9.4 - Prob. 9.4.5CPCh. 9.4 - When will a class have a default constructor?Ch. 9.5 - Which operator is used to access a data field or...Ch. 9.5 - What is an anonymous object?Ch. 9.5 - Prob. 9.5.3CPCh. 9.5 - Is an array an object or a primitive-type value?...
Ch. 9.5 - Prob. 9.5.5CPCh. 9.5 - What is wrong in the following code? 1. class Test...Ch. 9.5 - Prob. 9.5.7CPCh. 9.6 - Prob. 9.6.1CPCh. 9.6 - Prob. 9.6.2CPCh. 9.6 - Which packages contain the classes Date, Random,...Ch. 9.7 - Suppose the class F is defined in (a). Let f be an...Ch. 9.7 - Prob. 9.7.2CPCh. 9.7 - Can you invoke an instance method or reference an...Ch. 9.9 - Prob. 9.9.1CPCh. 9.9 - Prob. 9.9.2CPCh. 9.9 - In the following code, radius is private in the...Ch. 9.10 - Prob. 9.10.1CPCh. 9.10 - Show the output of the following program: public...Ch. 9.10 - Show the output of the following code:Ch. 9.10 - Prob. 9.10.4CPCh. 9.11 - What is wrong in the following code? 1public class...Ch. 9.12 - If a class contains only private data fields and...Ch. 9.12 - If all the data fields in a class are private and...Ch. 9.12 - Is the following class immutable? public class A {...Ch. 9.13 - What is the output of the following program?...Ch. 9.14 - Prob. 9.14.2CPCh. 9.14 - Prob. 9.14.3CPCh. 9 - (The Rectangle class) Following the example of the...Ch. 9 - (The Stock class) Following the example of the...Ch. 9 - (Use the Date class) Write a program that creates...Ch. 9 - Prob. 9.4PECh. 9 - (Use the GregorianCa1endar class) Java API has the...Ch. 9 - (Stopwatch) Design a class named StopWatch. The...Ch. 9 - (The Account class) Design a class named Account...Ch. 9 - (The Fan class) Design a class named Fan to...Ch. 9 - (Geometry: n-sided regular polygon) In an n-sided...Ch. 9 - Prob. 9.10PECh. 9 - (Algebra: 2 2linear equations) Design a class...Ch. 9 - (Geometry: intersecting point) Suppose two line...Ch. 9 - (The Location class) Design a class named Location...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Consider the adage Never ask a question for which you do not want the answer. a. Is following that adage ethica...
Experiencing MIS
The mass of the sun is 329,320 times that of the earth and its radius is 109 times the radius of the earth. (a)...
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Starting with a large wine glass and a small wine glass, fill the small glass with wine and then pour that wine...
Computer Science: An Overview (12th Edition)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
The article mentions that quantum computers will have tremendous processing power and revolutionize a number of...
Using MIS (10th Edition)
Abstract classes cannot ___________. a. be used as superclasses b. have abstract methods c. be instantiated d. ...
Starting Out with Java: From Control Structures through Data Structures (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
- What will be the output of the following Java code? class average { public static void main(String args[]) { double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5}; double result; result = 0; for (int i = 0; i < 6; ++i) result = result + num[i]; System.out.print(result/6); } } a) 16.34 b) 16.566666644 c) 16.46666666666667 d) 16.46666666666666arrow_forwardShow the derivation of the asymptotic run time, O(n), for each of the following methods. You may use the text highlighting technique shown in class, or list the individual Java statements along with the number of times each is executed as a function of the input size, n. public static void checkerboard(int n){ for (int row = 0; row < n; row++) { for (int col = 0; col < n; col++){ if ((row+col)%2 == 0) { // Print a single hashtag System.out.print("#"); } else { // Print a single space System.out.print(" "); } } // Complete the line System.out.println(); } }arrow_forwardimport java.util.Random; class Main { public static void main(String[] args) { Random rand = new Random(); int a = new int[100]; for (int i = 0; i < 100; i++) { a[i] = rand.nextInt(100); } print(a); System.out.println("---"); quicksort(a, 0, a.length - 1); print(a); } public static void print(int[] a) { for (int x : a) { System.out.println(x); } } public static void swap(int[] a, int p1, int p2) { int temp = a[p1]; a[p1] = a[p2]; a[p2] = temp; } public static int partition(int[] a, int left, int right) { int pivot = right; int p1 = left; int p2 = pivot - 1; while (p2 >= p1) { if (a[p1] > a[pivot]) { swap(a, p1, p2); swap(a, p2, pivot); p2 = pivot - 1; } else { p1++; } } return pivot; } public static void quicksort(int[] a, int left, int right) { if (left < right) { int p = partition(a, left, right); quicksort(a, left, p - 1);…arrow_forward
- Write down the outputs of the following java program public class Exam { String X = "Programming"; double Y = 3; static int N; Exam ( ) { N++ ; } public static void main(String args[]) { Exam s1 = new Exam ( ); Exam s2 = new Exam ( ); System.out.println("1. " + (s1.Y)); System.out.println("2. " + s1.X.replaceFirst("r", "S")); System.out.println("3. " + s2.N); } }arrow_forwardPlease sort out the following JAVA code....line by line. Run the code in Netbeans and provide screenshots to verify that it runs successfully. CODE: import java.io.*; import java.util.*; public class experiment { public static void main(String args[]) { Scanner in=new Scanner(System.in); int time[]=new int[10]; float weight[]=new float[10]; String get; char ch; int i=0; do{ try { System.out.print("\nEnter the time in seconds:"); time[i]=in.nextInt(); System.out.print("\nEnter the weight in kilograms:"); weight[i]=in.nextFloat(); i++; } catch(Exception e) { System.out.print("\nInvalid type"); } System.out.print("\n-----------------"); System.out.print("\n|Time\t|Weight\t|"); System.out.print("\n-----------------"); for(int x=0;x<i;x++) { System.out.print("\n|"+time[x]+"\t|"+weight[x]+"\t|"); System.out.print("\n-----------------"); } if(i==10) { for(int x=0;x<9;x++) { time[x]=time[x+1]; weight[x]=weight[x+1]; } i--; } System.out.print("\nDo you want to continue?(y/n) ");…arrow_forwardWhat will be the output of the following Java code? And Explain.? class char_increment { public static void main(String args[]) { char c1 = 'D'; char c2 = 84; c2++; c1++; System.out.println(c1 + " " + c2); } }arrow_forward
- Java- 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_forwardConsider the following piece of code: public static void main(String[] args) { BankAccount a = new BankAccount(500); BankAccount b = new BankAccount(a.getBalance()); BankAccount c = a; Identify all of the expressions that are true: a)(a.equals(500)) b)(a.equals(b)) c)(a == 500) d)(a == b) e)(a == c) f)(a.getBalance() == 500) g)(a.getBalance() == b.getBalance())arrow_forwardThis is the implementation of the Caesar cipher (Section5.3 in the textbook), which we discussed in class. Caesar cipher is a simple approach toencoding messages by shifting each letter in a message along the alphabet by aconstant amount.Your code will be similar to Listing 5.1, but you must use CircularArrayQueue.javainstead of the Java API queue. //5.1 import java.util.*;public class Codes { public static void main(String[] args) { int[] key = {5, 12, -3, 8, -9, 4, 10}; Integer keyValue; String encoded = "", decoded = ""; String message = "All programmer are playwrights and all "+"computers are lausy actors."; Queue<Integer> encodingQueue = new LinkedList<Integer>(); Queue<Integer> decodingQueue = new LinkedList<Integer>(); for (int scan=0; scan < key.length; scan++) { encodingQueue.add(key[scan]); decodingQueue.add(key[scan]); } for (int scan=0; scan < message.length();…arrow_forward
- What will be the output of the following Java Program? public class Main { public static void main(String args[]) { int arr[][] = new int[4][]; arr[0] = new int[1]; arr[1] = new int[2]; arr[2] = new int[3]; arr[3] = new int[4]; int i, j, k = 0; for (i = 0; i < 4; i++) { for (j = 0; j < i + 1; j++) { arr[i][j] = k; k++; } } for (i = 0; i < 4; i++) { for (j = 0; j < i + 1; j++) { System.out.print(" " + arr[i][j]); k++; } System.out.println(); } }}arrow_forwardThe following code; import java.io.File; import java.util.*; public class BinarySearch { public static int search(int key, int[] a) { return search(key, a, 0, a.length); } public static int search(int key, int[] a, int lo, int hi) { if (hi <= lo) return -(hi-1); int mid = lo + (hi - lo) / 2; int cmp = a[mid]-key; if (cmp > 0) return search(key, a, lo, mid); else if (cmp < 0) return search(key, a, mid + 1, hi); else{ if (a[mid+1]==key) return search(key,a,mid+1,hi); else{ return mid; } } } public static void main(String[] args) { String name= args[0]; int count=0; try{ Scanner scanner = new Scanner(new File(name)); while(scanner.hasNextInt()) { scanner.nextInt(); count++; } } catch(Exception e){} int a[] = new int[count]; int in=0; try{ Scanner scanner1 = new Scanner(new File(name)); while(scanner1.hasNextInt()) a[in++]=scanner1.nextInt(); } catch(Exception e){} System.out.println(search(Integer.parseInt(args[1]),a)); } } Do not know how to correct the error; Exception in…arrow_forwardIn Java trace the table for a while loop public class Main { public static void main(String[] args) { // Question 2 j = 30; x=5; for (int i=1;i<=2;i++) { while (j > 20) { j=j-x*i; ++x; }// end of while }// end of for j x i j<=2 j>20arrow_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
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License