Starting Out with Java: From Control Structures through Objects (6th Edition)
6th Edition
ISBN: 9780133957051
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
thumb_up100%
Chapter 16, Problem 5AW
What will the following
public class ReviewQuestion5
{
public static void main(String[] args)
{
int x = 10;
System.out.println(myMethod(x));
}
public static int myMethod(int num)
{
if (num <= 0)
return 0;
else
return myMethod(num - 1) + num;
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
public class Main
{
public static void main(String args[])
{
static_out obj1 - new static_out();
static_out obj2 = new static_out();
int a - 2;
obj1. add(a, a + 1);
obj2.add(5, a);
System.out.println(obj1.x +
}
4 -
6
7
9
+ obj2.y);
12
13
14
class static_out
{
static int x;
static int y;
void add(int a, int b)
{
x = a + b;
y - x + b;
15 -
16
17
18
19 -
20
I
21
22
23
24
O 77.4
66.4
O 79
O 97
O12 mt un o70 0 0o 234
111 111 111 12 2222
public class Test {
}
public static void main(String[] args) {
String str = "Salom";
System.out.println(str.indexOf('t));
}
public class TestShape
{
public static void main(String[] args)
{
/*
Circle c1 = new Circle(2.67);
System.out.println("c1: ");
System.out.println(c1.toString());
System.out.println();
Circle c2 = new Circle(3, false, "Red");
System.out.println("c2: ");
System.out.println(c2.toString());
System.out.println();
Rectangle r1 = new Rectangle(3, 2, true, "Blue");
System.out.println("r1: ");
System.out.println(r1.toString());
System.out.println();
Rectangle r2 = new Rectangle(3.2, 4, false, "Red");
System.out.println("r2: ");
System.out.println(r2.toString());
*/
}
}
Chapter 16 Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
Ch. 16.2 - It is said that a recursive algorithm has more...Ch. 16.2 - Prob. 16.2CPCh. 16.2 - What is a recursive case?Ch. 16.2 - What causes a recursive algorithm to stop calling...Ch. 16.2 - What is direct recursion? What is indirect...Ch. 16 - Prob. 1MCCh. 16 - This is the part of a problem that can be solved...Ch. 16 - This is the part of a problem that is solved with...Ch. 16 - This is when a method explicitly calls itself. a....Ch. 16 - Prob. 5MC
Ch. 16 - Prob. 6MCCh. 16 - True or False: An iterative algorithm will usually...Ch. 16 - True or False: Some problems can be solved through...Ch. 16 - True or False: It is not necessary to have a base...Ch. 16 - True or False: In the base case, a recursive...Ch. 16 - Find the error in the following program: public...Ch. 16 - Prob. 1AWCh. 16 - Prob. 2AWCh. 16 - What will the following program display? public...Ch. 16 - Prob. 4AWCh. 16 - What will the following program display? public...Ch. 16 - Convert the following iterative method to one that...Ch. 16 - Write an iterative version (using a loop instead...Ch. 16 - What is the difference between an iterative...Ch. 16 - What is a recursive algorithms base case? What is...Ch. 16 - What is the base case of each of the recursive...Ch. 16 - What type of recursive method do you think would...Ch. 16 - Which repetition approach is less efficient: a...Ch. 16 - When recursion is used to solve a problem, why...Ch. 16 - How is a problem usually reduced with a recursive...Ch. 16 - Prob. 1PCCh. 16 - isMember Method Write a recursive boolean method...Ch. 16 - String Reverser Write a recursive method that...Ch. 16 - maxElement Method Write a method named maxElement,...Ch. 16 - Palindrome Detector A palindrome is any word,...Ch. 16 - Character Counter Write a method that uses...Ch. 16 - Recursive Power Method Write a method that uses...Ch. 16 - Sum of Numbers Write a method that accepts an...Ch. 16 - Ackermarms Function Ackermanns function is a...Ch. 16 - Recursive Population Class In Programming...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
This optional Google account security feature sends you a message with a code that you must enter, in addition ...
SURVEY OF OPERATING SYSTEMS
Total Purchase A customer in a store is purchasing five items. The prices of the five items are as follows: Pri...
Starting Out with C++ from Control Structures to Objects (9th Edition)
Assume a telephone signal travels through a cable at two-thirds the speed of light. How long does it take the s...
Electric Circuits. (11th Edition)
Use the following tables for your answers to questions 3.7 through 3.51 : PET_OWNER (OwnerID, OwnerLasst Name, ...
Database Concepts (8th Edition)
What information is contained in the state of a process?
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
In the following exercises, write a program to carry out the task. The program should use variables for each of...
Introduction To Programming Using Visual Basic (11th 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
- class 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_forwardpublic class Geometry{public static void main(String[] args){//asks for user's choice Scanner in = new Scanner(System.in);displayMenu();selectOption(choice);System.out.println("Enter your choice (1-3): ");int choice1 = in.nextInt();System.out.println("Thanks for using the Geometry Calculator - Goodbye!");//Prints if input is a number that is not one of the choiceswhile(choice1 < 1 || choice1 > 3 ){System.out.println("Invalid choice. Please enter 1 - 3: ");choice1 = in.nextInt();}}/**Displays the menu*/public static void displayMenu(){System.out.println("Welcome to the Geometry Calculator Application");System.out.println("1. Calculate the Area of a Circle");System.out.println("2. Calculate the Area of a Rectangle");System.out.println("3. Calculate the Area of a Triangle");}/** This method calculates the area of the circle@return the area of the circle*/public static double circle()// calculates the area of the circle{Scanner in = new Scanner(System.in);System.out.println("What is…arrow_forwardclass main { public static void main(String args[]) { int x =2; int y =0; for(; y <10;++y) { if(y % x ==0) continue; elseif(y ==8) break; else System.out.print(y +" "); } } } Give result for the code Java Try to do ASAParrow_forward
- class class { public static void main(String args[]) { int a =5; int b =10; first: { second: { third: { if(a == b >>1) break second; } System.out.println(a); } System.out.println(b); } } } Give result for the code Java Try to do ASAParrow_forwardpublic 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_forwardclass Param3 { public int x; private void increase(int p) { x = x*p; } public void calculateX(int y) { increase(y); } public int getX() { return x; } } // in another class Param3 q3 = new Param3(); q3.x = 5; q3.calculateX(7); System.out.println(q3.getX()); what would be the answer for the last two lines ? also above were x = x*p do both x in here are the fields? wouldn't that be cnofusing?arrow_forward
- public class LabProgram { public static void main(String args[]) { Course cis162 = new Course(); int beforeCount; String toDrop; // Example students for testing cis162.addStudent(new Student("Henry", "Nguyen", 3.5)); cis162.addStudent(new Student("Brenda", "Stern", 2.0)); cis162.addStudent(new Student("Lynda", "Robison", 3.2)); cis162.addStudent(new Student("Sonya", "King", 3.9)); toDrop = "Stern"; beforeCount = cis162.countStudents(); cis162.dropStudent(toDrop); System.out.println("Course size: " + beforeCount + " students"); System.out.println("Course size after drop: " + cis162.countStudents() + " students"); } } import java.text.DecimalFormat; // Class representing a student public class Student { private String first; // first name private String last; // last name private double gpa; // grade point average // Student class constructor public Student(String f, String l, double g) {…arrow_forwardclass Variables { public static void main(String[] args) { .arrow_forwardpublic class MysteryReturn2 {3 public static void main(String[] args)4 {5 int x = 1;6 int y = 2;7 int z = 3;89 z = mystery(x, z, y);10 System.out.println(x + " " + y + " " + z);11 }1213 public static int mystery(int c, a, int b);14 {15 c--;16 a = 2 * b + c;17 b = a - 1;18 System.out.println(b + " " + c);1920 return a;21 }22 } 1. Line 13 contains 2 errors. What are they? 2. Rewrite line 13 with the errors identifed in Question 1 corrected.arrow_forward
- public class MysteryReturn2 {3 public static void main(String[] args)4 {5 int x = 1;6 int y = 2;7 int z = 3;89 z = mystery(x, z, y);10 System.out.println(x + " " + y + " " + z);11 }1213 public static int mystery(int c, a, int b);14 {15 c--;16 a = 2 * b + c;17 b = a - 1;18 System.out.println(b + " " + c);1920 return a;21 }22 } 1. The mystery method has three parameter variables, a, b, and c. What is the scope of these variables (that is, where can they be used by their name)?arrow_forwardpublic class Errors{public static void main (String[] args){System.out.println("Welcome to my first program!\n")String ageStr = "24 years";int age = Integer.parseInt(ageStr);System.out.println("I'm " + age + " years old.");int three = "3";int answerYears = age + three;System.out.println("Total number of years: " + answerYears);int answerMonths = answerYears * 12; System.out.println("In 3 years and 6 months, I'll be " + answerMonths + " months old");//Once you've corrected all the errors, the answer should be 330.}}arrow_forwardpublic class Course{String name;String dept;int number;public Course (String n, String d, int n){name = n;dept = d;number = n;}public String toString(){return "Course " + name + " in " + dept + " #: " + number;}public static void main (String [] args){Scanner in = new Scanner(System.in);add 10 lines using the scanner and saving them as strings The input for each line will be entered a String, a space, another String, and an int. Parse the input string into those three items and make an instance of Course. Add the new Course instance to a generic ArrayList of Course. print out each Course in the ArrayList.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
Memory Management Tutorial in Java | Java Stack vs Heap | Java Training | Edureka; Author: edureka!;https://www.youtube.com/watch?v=fM8yj93X80s;License: Standard YouTube License, CC-BY