English

Print the series 105, 5, 110, 10, 115, 15 ......... up to 12 terms.

Advertisements
Advertisements

Question

Print the series 105, 5, 110, 10, 115, 15 ......... up to 12 terms.

Code Writing
Advertisements

Solution

import java.util.*;
class clCommon
{
    void main()
    {
        int t1 = 105, t2 = 5;
        System.out.println("Numbers from " + t1 + " to " + t2 + " are:");        
        for(int r = 1; r <= 12; r++)
        {
            if(r % 2 != 0)
            {
                System.out.print(" " + t1);
                t1 = t1 + 5;
            }
            else
            {
                System.out.print(" " + t2);
                t2 = t2 + 5;
            }
        }
    }
}

Output:

Numbers from 105 to 5 are:

105 5 110 10 115 15 120 125 25 130 30

shaalaa.com
  Is there an error in this question or solution?
Chapter 11: Programs Overall - Loops [Page 251]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 11 Programs Overall
Loops | Q 4. | Page 251
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×