Java program to print numbers up to 100 which are divisible by 3 - Ask The Code

Print numbers up to 100 which are divisible by 3 | Java Programming Solution | AskTheCode

Problem:

Title: There was 3

I'm bored with just basic counting. How about we do some complex things this time? But I don't want to be associated with any number that's not divisible by 3.

Think you can handle this?


Instructions: Java program to print out all numbers from 1 to 100 that is divisible by 3, each in separate lines, using a for loop.


Output Sample:

3

6

9

12

15

18

21

93

96

99

Code:


public class Solution_ThereWas3{

public static void main(String[] args) {

for (int i = 3; i < 100; i++) {

if (i % 3 == 0) {

System.out.println(i);

}

}

}

}


6 views0 comments

Recent Posts

See All

Calculate BMI in Java | AskTheCode

Write a Java program that reads values for weight in kilograms and height in centimeters and prints out the BMI... interpretation of it...

"Believe you can and you're halfway there"