Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class numberOne {
- public static void main(String[] args) {
- /*
- *#1. Write java program using FOR loops for each of the following:
- * (a) Print the sum and average of all the EVEN numbers from 20 to 150.
- */
- int sum=0, average=0, num_count=0, product=1;
- for(int num=20; num<=150; num++) {
- if(num % 2 == 0) {
- sum += num;
- num_count++;
- average = sum / num_count;
- //System.out.println(num+ " ");
- }
- }
- System.out.println("Sum: " +sum);
- System.out.println("Average: " +average);
- //(b) Print the product of all the numbers from 25 to 15.
- for(int no=15; no<=25; no++) {
- product *= no;
- }
- System.out.println("Product: " +product);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement