Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6387923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:12:51+00:00 2026-05-25T03:12:51+00:00

I am doing a book exercise regarding the Ackermann function. I have one question

  • 0

I am doing a book exercise regarding the Ackermann function.

I have one question though. If I declare result but do not initialise it, the compiler complains that “variable result might not have been initialised”.

int result;

When I set it to default to 0, it does not complain.

int result = 0;

I thought that when one declares a variable with type int it defaults to 0 automatically.

Here’s the complete code:

public class Ackermann {
   public static int ack(int m, int n) {
     int result = 0;
     //int result;
     if (m == 0)
        result = n + 1;
     else if(m > 0 && n == 0)
        result = ack(m-1, 1); 
     else if(m > 0 && n > 0)
        result = ack(m-1, ack(m, n-1));
     return result;
   }   

   public static void main(String[] args) {
      System.out.println(ack(3, 3));  
   }   

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:12:52+00:00Added an answer on May 25, 2026 at 3:12 am

    Local variables are not initialized with default values. See the language specs for the ground truth.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As question states, I am doing homework which have 2 variables BOOK, and MAGAZINE
I am doing a book exercise (not homework, since i'm self-learning) in which I'm
I was doing an exercise on F# Wiki Book on List (scroll to the
As far as I can tell i'm doing everything by the book, but the
I'm doing exercise #9 from http://openbookproject.net/thinkcs/python/english2e/ch09.html and have ran into something that doesn't make
I'm doing a book exercise that says to write a program that generates psuedorandom
I am a beginner in Java and am doing an exercise from a book.
I'm doing the first chapter exercises on my Java book and I have been
i am doing an exercise from Orielly book, and they used that Twitter package
I am doing a a question in the book that asks me to write

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.