Computer Science, asked by chokhangbaa, 9 days ago

wap to print all the natural numbers from 100 to 1000 java pleaseee

Answers

Answered by sainiaarushkumar123
0

Write a Java Program to Print Natural Numbers from 1 to N using For Loop, and While Loop with an example.

Java Program to Print Natural Numbers from 1 to N Example 1

This program allows the user to enter any integer value(the maximum limit value). Next, this Java program displays all the natural numbers from 1 to maximum limit value (N) using For Loop.

// Java Program to Print Natural Numbers from 1 to N

import java.util.Scanner;

public class NaturalNumbers1 {

private static Scanner sc;

public static void main(String[] args)

{

int number, i;

sc = new Scanner(System.in);

System.out.print(" Please Enter any Number : ");

number = sc.nextInt();

for(i = 1; i <= number; i++)

{

System.out.print(i +"\t");

}

}

}

Java Program to Print Natural Numbers from 1 to N 1

First, we used the Java For loop to iterate from 1 to maximum value (Here, number = 6).

User entered value: number = 6

For Loop First Iteration: for(i = 1; i <= 6; i++)

Condition is True. So, i Value printed (i.e., 1)

Similar questions