Java Program to print Number series without using any loop

Following is the Java code to print Number srries without using any loop −


 Live Demo

public class Demo{
   public static void main(String[] args){
      int my_num = 0;
      System.out.println("The numbers without using loop have been printed below");
   public static void print_without_loop(int my_num){
      if(my_num <= 15){
         System.out.print(my_num +",");
         print_without_loop(my_num + 1);


The numbers without using loop have been printed below

A class named Demo contains the main function where a variable named ‘my_num’ is initialized to 0. A function named ‘print_without_loop’ is called. It is defined further wherein condition is checked if the number passedis greater than 15, if yes, then the number is printed beginning from 0 and incrementing it after every pass. Once the element 15 is reached, the condition exits.

Updated on: 07-Jul-2020


Kickstart Your Career

Get certified by completing the course

Get Started