Simple_while_iteration1
  • A function that calls itself, either directly or indirectly, is a recursive function.
  • If the method is called with a base class, it returns the output to itself and termination is also defined in this method.
     
Code :

package javatemplate1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class JavaTemplate1
{
public static void main(String[] args) throws IOException {
System.out.println("main block executing");
//
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Type a number :");
String str = "";
str = br.readLine();
int y = Integer.parseInt(str);int x=1;
for(int counter =1; counter <=y; counter++)
{
System.out.printf("%d round = %d\n", (counter ) , iteration(counter));
//
}
}

private static int iteration ( int n1 )
{

int iter=1, i = 1;
if(n1 == 1)  //test base case
{ return 1;
}
else
{
while(i < n1) // test iteration steps
{
iter = iter * n1;
n1--;
}
}
return iter;
}
}
 

Displays: