Consider the following program segment. Without using Dr.Java, What this program prints? (my class uses Dr.Java)
The answer that this program prints which i got was: 22
Is my answer correct?

public class sample {
public static void main(String[] args){
Sample x = new Sample();
int i = 10;
int b = x.g(i);
System.out.println(b + i);
public int f(int d){
int n = 0;
while(n*n < d){
return n-1;
public int g(int a){
int b = 0;
int c;
for(int n = 0; n < a; n++){
c = f(n);
b = b + c;
return b;

  1. 👍 0
  2. 👎 0
  3. 👁 150
  1. I assume your answer is correct, if you ran the code and that's what it printed.

    1. 👍 0
    2. 👎 0
    posted by oobleck
  2. i didn't run the program (i swear). i only looked the the program and i was think if the answer was 22

    1. 👍 0
    2. 👎 0
  3. so, run it, and see whether you were right!

    1. 👍 0
    2. 👎 0
    posted by oobleck
  4. ok thanks

    1. 👍 0
    2. 👎 0

Respond to this Question

First Name

Your Response

Similar Questions

  1. programming

    I am having trouble writing this program for java. can anybody help write a program that prints the letter X composed of asterisk.

    asked by Riley on February 5, 2010
  2. Programming Java

    I am learning Java in programming right now. I need to write a program that should have an output like this: The program says "Type ten names". Then ten names sould be typed a person. Then the program chooses a random name from

    asked by Valerie on November 16, 2017
  3. Programming

    Widget company runs a small factory that makes several types of nuts and bolts. They employ (a)1 (b)2 (c)3. Each factory worker can work a maximum of (a)40 hours normal working hours per week. All hours over 40 are paid as

    asked by Jessica on April 28, 2017
  4. programming

    java, write a program that prints out the letter X composed of asterisks (*) reply soon

    asked by patrick on February 4, 2010
  5. java

    Write a java application that finds the smallest of several integers. Prompt the user for the number of integers that will be input, then prompt the user for that number of integers. Evaluate the integers to determine the smallest

    asked by saleh on October 21, 2012
  6. java/programming Please Help Me!!

    I did this java program, i just want someone to correct it. In this exercise, you will be writing a simple java program to explore using multi methods. The program is consists of one class (MultiMethods). It will hold more than

    asked by ghost on February 21, 2019
  7. programming

    Having troube with java, i am not a regular programmer, if anybody can help me out writting this program: write a program that takes two numbers from the java console representing, respectively, an investment and an interest

    asked by John on February 4, 2010
  8. Java Programming

    I'm new to Java and I'm not sure how to write the source code for this problem I got in class... Write a java program using the while and if statement that will accept ten student grades and that will display the sum of the

    asked by Samantha on June 10, 2013
  9. programming

    Write a program which allows user to enter 10 student names and scores for Java programming 1 and Java programming 2. Allow user to choose which course they want to enter the record for. Use the loop to ask input from user. The

    asked by Java on March 2, 2014
  10. Java

    I am trying to write an algorithm for my JAVA class and am having some issues....if I were to post my program is there anyone on here that could help me figure out what I am doing wrong? Thanks

    asked by Mike on April 4, 2008

More Similar Questions