For Loop Multiplying Number

We Are Going To Discuss About For Loop Multiplying Number. So lets Start this Java Article.

For Loop Multiplying Number

  1. For Loop Multiplying Number

    You don't need to change originalNumber at all – just multiply i by originalNumber:
    int originalNumber = 1; for (int i = 1; i <= 10000; i++) { int multiple = originalNumber * i;

  2. For Loop Multiplying Number

    You don't need to change originalNumber at all – just multiply i by originalNumber:
    int originalNumber = 1; for (int i = 1; i <= 10000; i++) { int multiple = originalNumber * i;

Solution 1

You don’t need to change originalNumber at all – just multiply i by originalNumber:

int originalNumber = 1;
for (int i = 1; i <= 10000; i++) {
    int multiple = originalNumber * i;
    // Use multiple however you want to
}

To get all the multiples of 2, you’d set originalNumber to 2, etc.

Original Author Jon Skeet Of This Content

Solution 2

You ask for version without additional variable:

int originalNumber = 1;
for (int multiple = originalNumber; multiple <= 10000; multiple += originalNumber) {
    // Use multiple however you want to
}

Original Author Roman Łomowski Of This Content

Solution 3

 int n = scanner.nextInt();
       for (int i = 1; i <= 10;  i++){
         int multiple = i * n;
         System.out.println(n + " x " + i + " = " + multiple);
        } 

You can try this code, it prints any multiple till 10;
Your Output (stdout)
2 x 1 = 2
2 x 2 = 4

2 x 10 = 20

Original Author Sean Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment