What output will be produced by the following code?
public class Demo
{
public static void main (String[] args)
{
System.out.printingln (“The output is:”);
bar (11156);
System.out.println ();
}
public static void bar (int number)
{
if (number > 0)
{
int d = number % 10;
boolean odd = (number / 10) % 2 == 1;
bar(number / 10);
if (odd)
System.out.print (d / 2 + 5);
else
System.out.print (d / 2);
}
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Introduction To Programming Using Visual Basic (11th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Programming in C
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Problem Solving with C++ (10th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- 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 partarrow_forwardWhat 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_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_forward
- What gets printed when the following program is compiled and run? class xyz { public static void main(String args[]) { int i,j,k; for (i = 0; i < 3; i++) { for(j=1; j < 4; j++) { for(k=2; k<5; k++) { if((i == j) && (j==k)) System.out.println(i); }}}}} a: 0 b: 1 c: 2 d: 3arrow_forwardWhat will be the output of the following Java program? class Output { public static void main(String args[]) { Double i = new Double(257.5); Double x = i.MAX_VALUE; System.out.print(x); } }arrow_forwardWhat will happen when you compile and run the following code? #1. public class Test{ public static void main(String[] args){ int a = 10, b = 0; while( a + 2 < 10 || b - 2 > 0){ System.out.println(a); } } } #2. public class Test{ public static void main(String[] args){ int a = 0, b = 10; while(b - 40 > 0){ b -= 2; while(a + 12 < 10){ a += 2; if(a == b) continue; System.out.print(a + " " + b + ", "); } } } } show the output and solution, its java languagearrow_forward
- Correct any mistake(s) in the following Java code and write your answer on the right (d) public static void main(String[] args){ printSalary( ); System.out.println(“Salary is ”+salary); } public static void printSalary( ) { double salary=20000; System.out.println(“Salary is ”+salary); } (e) public static void doubleNum(int num){ num=2*num; return num; }arrow_forwardI have my code below and I am stuck for days at displaying the number of available burgers and customer waiting. What should be edited to make the program work? sample output is given below. import java.util.Scanner;import java.util.Random; class Exam implements Runnable { private String cName = new String(""); public Exam (String cName, int x) { this.cName = cName; this.x = x; } static int x; @Override public void run() { Random r = new Random(); int j=0, avail=0; for(int i = 1; i <= this.x; i++) { Exam e[] = new Exam [this.x]; if (cName == "Consumer #1" || cName == "Consumer #2"){ if (i > 0 && j == 0){ System.out.println(cName + " of Thread #" + i + " buys 1 burger # of available burgers [" + avail + "] Customer(s) waiting [" + j++ + "]"); }else{ avail = i - 1; System.out.println(cName +…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. import java. util.Random; import java.util. Scanner; import java.util.regex.*; public class HiLOGame{ public static void main( String(] args){ final int MAX POINT = 1000- int point = MAX POINT: int numberOfGuess = 0; do { numberOfGuess++: showStatus(point); int point ToRisk = getPointToRisk("Enter point to risk? ", point); String option = getHiLoOption ("Enter either Hi or Lo?"); int magicNumber = getMagicNumber(1, 13); /I for debug //System.out.printf(String.format ("Magic number: %d%n",. magicNumber)); if (isWon(option, magicNumber)) { point += pointToRisk: System.out.printin("You Won this game."); } else f point -= pointToRisk: System.out.printin("You Lost this game."); } }while (point > 0): report(MAX POINT, numberOfGuess); System.exit(0); }…arrow_forward
- 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; } }arrow_forwardWhat is the output of the following code? Explain each line of the console output in yourown words. (HINT: if there are errors, please explain why the errors occur)enum Color {WHITE, YELLOW;}public class Bus {public Color getColor(){return Color.WHITE;}public static void main(String args[]){Bus number1 = new Bus(); Bus number11 = new SchoolBus();SchoolBus number111 = new SchoolBus();System.out.println("The colors of my Buses are: \n" +number1.getColor() + ", " + number11.getColor() + ", " +number111.getColor());SchoolBus myBus = (SchoolBus)(number1);}}class SchoolBus extends Bus {public Color getColor(){return Color.YELLOW;}}arrow_forwardTHIS IS IN JAVA Question: Given a line of text as input, output the number of characters excluding spaces, periods, exclamation points, or commas. Ex: If the input is: Listen, Mr. Jones, calm down. the output is: 21 Note: Account for all characters that aren't spaces, periods, exclamation points, or commas (Ex: "r", "2", "?"). My incorrect code: import java.util.Scanner; public class LabProgram { public static void main(String[] args) {Scanner scnr = new Scanner(System.in); String userText; int count = 0; userText = scnr.nextLine(); for (int i = 0; i < userText.length(); i++) { if (userText.charAt(i) != ' ' && userText.charAt(i) != '.' && userText.charAt(i) != ',') count++; } System.out.println(count); }} An example/hint i'm given to compare to my code as to why i'm getting it wrong: Output differs. See highlights below. Input Howdy! Your output 6 Expected output 5 Please…arrow_forward
- 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