public class main{
public static void main(String[] args){
---
int sum = 0;
---
for (int i = 0; i <= 10; i++) {
---
sum += i;
---
}
System.out.println(sum);
---
}
}
public class main{
public static void main(String[] args){
for (int i = ___A___; i <= ___B___; i++)
if (___C___ % ___D___ == ___E___)
System.out.println(i);
}
}
2.
Q2: Fill in the blanks in the above code to create a program that will print the even numbers between 1 and 20.
Q3: Put the code in the right order to create a program that will generate an integer between 0 and 10,000 (inclusive), print the number, calculate and print the number of digits in the number.
import java.util.*;
public class main{
public static void main(String[] args){
---
Random r = new Random();
int x = r.nextInt(10001);
---
int digits = 0;
int y = x;
---
while (y > 0) {
---
digits++;
y = y/10;
---
}
---
System.out.println(x + " has " + digits + " digits.");
---
}
}
Q4: Put the code in the right order to create a program that will print out all Armstrong numbers between 1 and 500. If the sum of the cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number. For example, 153 = (1*1*1) + (5*5*5) + (3*3*3)
import java.util.*;
public class main{
public static void main(String[] args){
---
for (int i = 100; i <= 500; i++) {
---
int dig1 = i/100;
int dig2 = (i/10)%10;
int dig3 = i%10;
---
int total = Math.pow(dig1,3) + Math.pow(dig2,3) + Math.pow(dig3,3);
---
if (total == i)
---
System.out.println(i + " Armstrong number.");
---
} // end for
---
}
}