Video 23 (ch5)

Yash
0


Program:-

https://drive.google.com/file/d/1jyUjCphzMJYO8laNntSx4bwJqNfQn9Zx/view?usp=drivesdk


import java.util.Scanner;

public class For_loop {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in); 

System.out.println("The first ten natural numbers are:");

for(int a = 1;a<=10;a++){

    System.out.println(a);

    }

//Q. write a program to print first 20 odd numbers using a for loop.

System.out.println("The first twenty odd numbers are:");

for(int i = 0; i<20;i++)

{

    System.out.println(2*i+1);

    }

    //Q.write a program to print first 10 natural nimbers in reverse order.

    System.out.println("The first ten natural numbers in reverse order:");

    for(int b = 10;b>=0;b--){

        System.out.println(b);

        }

        //by taking input from user.

    System.out.print("Enter how many odd numbers do you want starts form 0:");

    int c = sc.nextInt();

    for(int d = 0 ;d<c;d++){

        System.out.println(2*d+1);

        }

}

}

Tags

Post a Comment

0 Comments
Post a Comment (0)
To Top