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.13, Problem 9.13.1CP
What is the output of the following
public class Test {
private static int = 0;
private static int j = 0;
public static void main (String[] args) {
int i = 2;
int k = 3;
{
int j = 3 ;
System.out.println("i + j is " + i + j );
}
k=i + j;
System.out.pr intln ("k is" + k);
System.out.pr intln("j is" + j);
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
What is wrong in the following method in JAVA?public class Test {public static void main(String[] args) {xMethod(1234567);}public static void xMethod(double n) {if (n != 0) {System.out.print(n);xMethod(n / 10);}}}
What is the output of the following Java program?
class Test
{
public static void main (String args[])
{
for(int i=0; 0; i++)
{
System.out.println("Hello World");
}
}
}
Hello World
0, 1, 2, 3
0, 1, 2, 3, 4
Compile-time error because the for loop demands a boolean value in the second part
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);
} }
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
Which category of C++ reference variables always produces aliases?
Concepts of Programming Languages (11th Edition)
Consider the adage Never ask a question for which you do not want the answer. a. Is following that adage ethica...
Experiencing MIS
Rewrite the temperature conversion program of Section 1.2 to use a function for conversion.
C Programming Language
Why is it good advice to indent all the statements inside a set of braces?
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
The ________ object is assumed to exist and it is not necessary to include it as an object when referring to it...
Web Development and Design Foundations with HTML5 (8th Edition)
A __ structure can execute a set of statements only under certain circumstances. a. sequence b. circumstantial ...
Starting Out with Programming Logic and Design (4th 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
- Give the output of the following program public class QuizProblem { public static String quizProb(int i, int j, String myString) { String answer = ""; if(i > j) { return answer; } else { return quizProb(i+1,j,myString) + myString.charAt(i); } } public static void main(String[] args) { String testStr="marshall"; System.out.println(quizProb(0,testStr.length()-1,"marshall")); } }arrow_forwardWhat is the output of the following program and show all your workings? public class Main{public static void main(String[] args) {System.out.printin(mystery(5));}static int mystery(int num){if(num <= 1)return 1;else{return mystery(num-1) + mystery(num—2) ;}arrow_forwardI need help to Fill in the two methods in the .java file in the following below: public class JavaProject{public static int[][] sum(int[][] A, int[][] B){//TODO: Your code should go herereturn null; //This line is wrong and should be changed.} public static int[][] cutOffTheCrust(int[][] input){//TODO: Your code should go here return null; //This line is wrong and should be changed.}public static int[][] getSubsetRows(int[][] input, int row_start, int row_end){//TODO: Your code should go here return null; //This line is wrong and should be changed.}public static void main(String[] args){System.out.println("=== TESTING sum Test 1 ===");int[][] input1 = {{1, 5},{4, 6}};int[][] input2 = {{7, 3},{5, 4}};int[][] result = sum(input1, input2);printArray(result); System.out.println("=== TESTING sum Test 2 ===");int[][] input7 = {{1, 5, 1, 0},{4, 6, -3, 7}};int[][] input8 = {{7, 3, 1, 1},{5, 4, 0, -2}};result = sum(input7, input8);printArray(result); System.out.println("=== TESTING…arrow_forward
- In the following program, explain the relationship between the outputs on line 8 and 9: class PrePostDemo { public static void main(String[] args){ int i = 10; i++; out.println(i); ++i; out.println(i); out.println(++i); out.println(i++); out.println(i); } }arrow_forwardI did part A but I really need all parts of part B answered I want the code to continue after 0 with negative numbers and I need the guesses to show up at the end that shows how many guesses it took before the user ran out of points and my code is messed up. import java.util.*;public class HiLo { public static void main(String[] args) { final int MAX_POINT = 1000; int point = MAX_POINT; int min = 1; int max = 13; int guess = 0; System.out.println("High Low Game."); System.out.println("RULES."); System.out.println("1. Numbers 1 through 6 are low ."); System.out.println("2. Numbers 8 through 13 are High ."); System.out.println("3. Numbers 7 is neither high or Low."); do { displayPoints(point); int pointToRisk = enterPointsToRisk(point); String option = predictHiLo("\nPredict <1=High, 0=Low>: "); int computerRandomNum = randomNumgen(min, max); if…arrow_forwardRe-write this program using Iterators but without changing the meaning and consequently producing the same output. class TwoDArray { public static void main(String args[]) { int i, j, k = 0, twoD[][] = new int[4][5]; for(i = 0; i < 4; i++) for (j = 0; j < 5; j++) twoD[i][j] = k++; for(i = 0; i < 4; i++) { for(j = 0; j < 5; j++) System.out.print(twoD[i][j] + " "); System.out.println(); } }arrow_forward
- Write static Java method that will accept two integer variables and will return substraction of both numbers Thanks in advancearrow_forwardPROGRAM SIMULATION. Understand the given JAVA program and write the output. b. public class ChangeIt { public void doIt( int[] z ) { z[0] = 0; } } public class TestIt { public static void main ( String[] args ) { int[] myArray = {1, 2, 3, 4, 5} ; ChangeIt.doIt(myArray ); for (int j=0; j<myArray.length; j++ ) System.out.print( myArray[j] + " " ) ; } }arrow_forward4. What will be the output of following Java program? class Test{ public static void main (String[] args) { int arr1[] = {1, 2, 3}; int arr2[] = {1, 2, 3}; if (arr1.equals(arr2)) System.out.println("Same"); else System.out.println("Not same"); }}arrow_forward
- 5. What will be the output of following Java program? class Test{public static void main (String[] args){ int arr1[] = {1, 2, 3}; int arr2[] = {1, 2, 3}; if (arr1 == arr2) System.out.println("Same"); else System.out.println("Not same"); }}arrow_forwardWhat will be the output of the following program snippet: With static scoping a) 2 4 b) 3 1 c) 2 5 d) 3 4 With dynamic scoping a) 2 4 b) 3 1 c) 2 5 d) 3 4 int a, b; void print() { printf("%d %d", a, b); } int fun1(){ int a,c a= 0; b = 1; c = 2; return c; } void fun2() { int b; a=3; b=4; print(); } int main(){ a=fun1(); fun2(); }arrow_forward3. What will be the output of the following Java Program? class Test { public static void main(String args[]) { int arr[] = new int[2]; System.out.println(arr[0]); System.out.println(arr[1]); }}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