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 2.5, Problem 2.5.1CP
Identify and fix the errors in the following code:
- 1 public class Test {
- 2 public static void main(Str1ng[] args) {
- 3 int i = k + 2;
- 4 System.out.println (i);
- 5 }
- 6 }
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Fix 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 =…
Analyse the following code.
public class Test {
int x;
public Test(String t) {
System.out.println("Test");
}
public static void main(String[] args) {
Test test = new Test();
System.out.println(test.x);
}
}
A.
The program has a compile error because you cannot create an object from the class that defines the object.
B.
The program has a compile error because System.out.println method cannot be invoked from the constructor.
C.
The program has a compile error because x has not been initialized.
D.
The program has a compile error because Test does not have a default constructor.
C#
Method
Chapter 2 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 2.2 - Identify and fix the errors in the following code:...Ch. 2.3 - How do you write a statement to let the user enter...Ch. 2.3 - Prob. 2.3.2CPCh. 2.4 - Prob. 2.4.1CPCh. 2.5 - Identify and fix the errors in the following code:...Ch. 2.6 - Identify and fix the errors in the following code:...Ch. 2.7 - Prob. 2.7.1CPCh. 2.8 - Prob. 2.8.1CPCh. 2.8 - Translate the following algorithm into Java code:...Ch. 2.9 - Prob. 2.9.1CP
Ch. 2.9 - Prob. 2.9.2CPCh. 2.9 - Prob. 2.9.3CPCh. 2.9 - Prob. 2.9.4CPCh. 2.9 - Prob. 2.9.5CPCh. 2.9 - Prob. 2.9.6CPCh. 2.9 - Write a statement to display the result of 23.5.Ch. 2.9 - Suppose m and r are integers. Write a Java...Ch. 2.10 - How many accurate digits are stored in a f1oat or...Ch. 2.10 - Prob. 2.10.2CPCh. 2.10 - Prob. 2.10.3CPCh. 2.10 - Which of the following are correct literals?...Ch. 2.11 - How would you write the following arithmetic...Ch. 2.12 - Prob. 2.12.1CPCh. 2.13 - Prob. 2.13.1CPCh. 2.14 - Which of these statements are true? a. Any...Ch. 2.14 - Show the output of the following code: int a = 6;...Ch. 2.15 - Prob. 2.15.1CPCh. 2.15 - Prob. 2.15.2CPCh. 2.15 - Show the following output: float f =12.5F; int i =...Ch. 2.15 - If you change (int) (tax 100) / 100.0 to (int)...Ch. 2.15 - Prob. 2.15.5CPCh. 2.15 - Write an expression that rounds up a double value...Ch. 2.16 - How would you write the following arithmetic...Ch. 2.17 - Show the output of Listing 2.10 with the input...Ch. 2.18 - Can you declare a variable as int and later...Ch. 2.18 - Prob. 2.18.2CPCh. 2.18 - Will overflow cause a runtime error?Ch. 2.18 - Prob. 2.18.4CPCh. 2 - (Convert Celsius to Fahrenheit) Write a program...Ch. 2 - (Compute the volume of a cylinder) Write a program...Ch. 2 - (Convert feet into meters) Write a program that...Ch. 2 - (Convert pounds into kilograms) Write a program...Ch. 2 - (Financial application: calculate tips) Write a...Ch. 2 - (Sum the digits in an integer) Write a program...Ch. 2 - (Find the number of years) Write a program that...Ch. 2 - (Current time) Listing 2.7. ShowCurrentTime.java,...Ch. 2 - (Physics: acceleration) Average acceleration is...Ch. 2 - (Science: calculating energy) Write a program that...Ch. 2 - (Population projection) Rewrite Programming...Ch. 2 - (Physics: finding runway length) Given an...Ch. 2 - (Financial application: compound value) Suppose...Ch. 2 - (Health application: computing BMI) Body Mass...Ch. 2 - (Geometry: distance of two points) Write a program...Ch. 2 - (Geometry: area of a hexagon) Write a program that...Ch. 2 - (Science: wind-chill temperature) How cold is it...Ch. 2 - (Print a table) Write a program that displays the...Ch. 2 - (Geometry: area of a triangle) Write a program...Ch. 2 - (Financial application: calculate interest) If you...Ch. 2 - (Financial application: calculate future...Ch. 2 - (Financial application: monetary units) Rewrite...Ch. 2 - (Cost of driving) Write a program that prompts the...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Given a persons year of birth, the Birthday Wizard can compute the year in which the persons nth birthday will ...
Java: An Introduction to Problem Solving and Programming (8th Edition)
This optional Google account security feature sends you a message with a code that you must enter, in addition ...
SURVEY OF OPERATING SYSTEMS
This key word indicates that a class inherits from another class. a. derived b. specialized c. based d. extends
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
For the circuit shown, use the node-voltage method to find v1, v2, and i1.
How much power is delivered to the c...
Electric Circuits. (11th Edition)
What is the difference between virtual memory and main memory?
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Fill in the blanks in each of the following statements: The do...while statement tests the loop-continuation co...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
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
- Explainarrow_forwardpublic class Test { } public static void main(String[] args){ int a = 10; System.out.println(a*a--); }arrow_forward(3) public static void test_b(int n) { if (n>0) test_b(n-2); System.out.println(n + " "); Consider the following method: What is printed by the call test_b(4)? A. 0 2 4 B. 0 2 C. 2 4 D. 4 2 E. 4 20 3 (4) What is the efficacy class of +? n 3 A: ©(1) B: O (log n) C: O (n) D: O (n log n) E: Θ n)arrow_forward
- Do not copy from other websites I will Upvotearrow_forward10. 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++; }arrow_forwardpublic static void main(String [] args) { // Step 2: Construct a Day object representing today // and assign it to a variable called aDay // Step 3: Construct a Day object representing the day for our Exam1 on March 1, 2022, and assign it to a variable called examOne // // // Step 4: Declare three integer variables called year, month and day with initial values of 2022, 4, 12. // // 4 // Step 5: Construct a Day object using the three variables and assign it to a variable called examTwo 6. :7 28 29 // // Step 6: Display the three days on separate lines without any messages 30 31 // 32 33 // Step 7: Display the number of days as a positive integer between the two exams with a message 34 35 // 36 // "Number of days between the two exams: " 37 38 39 // Step 8: Update aDay to the day two days later 40 41 // Step 9: Print the year, month and day of aDay, one value per line without any messages 42 43 // 44 45 } 46 47arrow_forward
- javaarrow_forwardI am getting an error Error: Main method not found in class Course, please define the main method as: public static void main(String[] args)arrow_forwardclass operators { public static void main(String args[]) { int x = 8; System.out.println(++x * 3 + " " + x); } } Give result for the code Java Try to do ASAP ?arrow_forward
- Statement that increases numPeople by 5. Ex: If numPeople is initially 10, the output is: There are 15 people.arrow_forwardThe following code segment has an error. Find the error and suggest a correction.arrow_forward/** * A tester program for the PaintJob class. * public class PaintJobTester { public static void main(String[] args) { PaintJob job = new PaintJob(10.5, 9.0); System.out.printf("Room length: %.1f%n", job.getLength()); System.out.println("Expected: 10.5"); System.out.printf("Room width: %.1f%n", job.getWidth()); System.out.println("Expected: 9.0"); System.out.printf("Surface area: %.2f%n", job.surfaceArea()); System.out.println("Expected: 368.72"); System.out.printf("Paint cost: %.2f%n", job.costOfPaint()); System.out.println("Expected: 39.27"); System.out.printf("Total cost: %.2f%n", job.totalJobCost()); System.out.println("Expected: 139.27"); job.setDimensions(15, 12); System.out.printf("Room length: %.1f%n", job.getLength()); System.out.println("Expected: 15.0"); System.out.printf("Room width: %.1f%n", job.getWidth());…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
The Top Down Approach to Software Development; Author: Christopher Kalodikis;https://www.youtube.com/watch?v=v9M8LA2uM48;License: Standard YouTube License, CC-BY