JAVA CODING EXAMPLES: PROGRAMMING FOR BEGINNERS by KING J

JAVA CODING EXAMPLES: PROGRAMMING FOR BEGINNERS by KING J

Author:KING, J [KING, J]
Language: eng
Format: epub
Published: 2020-08-18T16:00:00+00:00


Using while loop to print numbers from 1 to N

PROGRAM

import java.util.Scanner;

public class Print_1_To_N_UsingWhile

{

​ public static void main(String[] args)

​ {

​ //loop counter initialisation

​ int i =1;

​ //create object of scanner class

​ Scanner Sc = new Scanner(System.in);

​ // enter the value of " n "

​ System.out.print("Enter the value n : ");

​ // read the value.

​ int n = Sc.nextInt();

​ System.out.println("Numbers are : ");

​ while(i<=n)

​ {

​ System.out.println(i);

​ i++;

​ }

​ }

}

Output

Enter the value n : 15

Numbers are :

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.