0% found this document useful (0 votes)
60 views1 page

Programiz Online Java Compiler Example

The document contains a Java program that defines a class 'HelloWorld' with a main method. It initializes an integer 'n' and calls a recursive function 'fun' to process 'n' based on its evenness or oddness. The function counts how many steps it takes to reduce 'n' to zero and outputs that count.

Uploaded by

Kris Upadhyay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views1 page

Programiz Online Java Compiler Example

The document contains a Java program that defines a class 'HelloWorld' with a main method. It initializes an integer 'n' and calls a recursive function 'fun' to process 'n' based on its evenness or oddness. The function counts how many steps it takes to reduce 'n' to zero and outputs that count.

Uploaded by

Kris Upadhyay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Programiz PRO

Online Java Compiler

[Link] Output

1 class HelloWorld {
2 public static void main(String[]
args) {
3 int n=14;
4
5 [Link](fun(n,0));
6 }
7 static int fun(int n, int count){
8 if(n==0){
9 return count;
10 }
11 if(n%2==0){
12 return fun(n/2,count++);
13 }
14 else{
15 return fun(n-1,count++);
16 }
17 }
18

Run

You might also like