Java Assignment - hyrtutorials
1. Print 1 to 100 values
2. Print even numbers between 200 and 500
3. Print the numbers which are divisible by 7 for the range of 150 to 200
Java Code:
public class Assignment {
public static void main(String[] args) {
// 1. Print 1 to 100 values
System.out.println("Numbers from 1 to 100:");
for (int i = 1; i <= 100; i++) {
System.out.print(i + " ");
}
System.out.println("\n");
// 2. Print even numbers between 200 and 500
System.out.println("Even numbers between 200 and 500:");
for (int i = 200; i <= 500; i++) {
if (i % 2 == 0) {
System.out.print(i + " ");
}
}
System.out.println("\n");
// 3. Print numbers divisible by 7 between 150 and 200
System.out.println("Numbers divisible by 7 between 150 and 200:");
for (int i = 150; i <= 200; i++) {
if (i % 7 == 0) {
System.out.print(i + " ");
}
}
}
}