India's Largest Free Online Education Platform

Java program to print numbers from 1 to N using for loop

Java program to print numbers from 1 to N using for loop

Code:

import java.util.Scanner;
public class Counting_no
{
    public static void main(String args[])
    {
        Scanner Sc= new Scanner(System.in);
        System.out.println("Enter the upper limit uptill you want to print numbers from 1");
        int n= Sc.nextInt();
        for(int i=1;i<=n;i++)
            System.out.println(i);

    }
}

 

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!