DEV Community

Kaviya.k
Kaviya.k

Posted on

while loop:

Number series:

1.Look at this series: 7, 10, 8, 11, 9, 12, ... What number should come next?

Let's analyze the pattern in this series:

7 → 10 (add 3)
10 → 8 (subtract 2)
8 → 11 (add 3)
11 → 9 (subtract 2)
9 → 12 (add 3)

The pattern alternates between adding 3 and subtracting 2.Since the last operation was adding 3 (from 9 to 12), the next operation should be subtracting 2.

program 1:

public class Series {

    public static void main(String[] args) {
        int no=7;
        int count=0;
    while(count<=6) {
            System.out.println(no);
            no=no+3;
            System.out.println(no);
            no=no-2;
            count=count+2;
        }
    }

}

output:
7
10
8
11
9
12
10
13

Enter fullscreen mode Exit fullscreen mode

2.Look at this series: 36, 34, 30, 28, 24, ... What number should come next?

Let's analyze the pattern:

36 → 34 (subtract 2)
34 → 30 (subtract 4)
30 → 28 (subtract 2)
28 → 24 (subtract 4)

The pattern alternates between subtracting 2 and subtracting 4.so the next operation should be to subtract 2 from 24.

program 2:

package Numbers;

public class Series1 {

    public static void main(String[] args) {
        int no=36;
        int count=0;
        while(count<5) {
            System.out.println(no);
            no=no-2;
            System.out.println(no);
            no=no-4;
            count=count+2;
        }

    }

}
output:
36
34
30
28
24
22
Enter fullscreen mode Exit fullscreen mode

3.Look at this series: 53, 53, 40, 40, 27, 27, ... What number should come next?

let's look at the pattern:

53 → 53 (no change)
53 → 40 (subtract 13)
40 → 40 (no change)
40 → 27 (subtract 13)
27 → 27 (no change)

The pattern alternates between no change and subtracting 13. the next step should be subtracting 13 from 27.

program3:
package Numbers;

public class Series2 {

    public static void main(String[] args) {
        int no=53;
        int count=0;
        while(count<=5){
            System.out.println(no);
            System.out.println(no);
            no=no-13;
            count=count+2;
        }
    }

}
output:
53
53
40
40
27
27

Enter fullscreen mode Exit fullscreen mode

4.Look at this series: 21, 9, 21, 11, 21, 13, 21, ... What number should come next?

Let's break down the pattern:

21 → 9 (subtract 12)
9 → 21 (add 12)
21 → 11 (subtract 10)
11 → 21 (add 10)
21 → 13 (subtract 8)

The pattern alternates between subtracting a number and then adding the same or a different number.
The pattern for subtraction follows: 12, 10, 8 (subtracting 2 each time) the next step should be to add 8 (following the alternating pattern of addition and subtraction).13 + 8 = 21

program 4:
package Numbers;

public class Series3 {

    public static void main(String[] args) {
        int no=58;
        int count=1;
        while(count<=5) {
            System.out.println(no);
            no=no-6;
            count=count+1;
        }
    }

}
output:
58
52
46
40
34

Enter fullscreen mode Exit fullscreen mode

5.Look at this series: 3, 4, 7, 8, 11, 12, ... What number should come next?

Let's look at the pattern:

3 → 4 (add 1)
4 → 7 (add 3)
7 → 8 (add 1)
8 → 11 (add 3)
11 → 12 (add 1)

The pattern alternates between adding 1 and adding 3. the next operation should be adding 3.

program 5:
package Numbers;

public class Series4 {

    public static void main(String[] args) {
        int no=3;
        int count=1;
        while(count<=6){
            System.out.println(no);
            no=no+1;
            System.out.println(no);
            no=no+3;
            count=count+2;
        }
        }

}
output:
3
4
7
8
11
12
Enter fullscreen mode Exit fullscreen mode

6.Look at this series: 8, 22, 8, 28, 8, ... What number should come next?

Let's analyze the pattern:

8 → 22 (add 14)
22 → 8 (subtract 14)
8 → 28 (add 20)
28 → 8 (subtract 20)

The pattern alternates between adding a number and then subtracting the same number, with the numbers being added or subtracted increasing by 6 each time.
The last operation was subtracting 20, so the next step should be to add 26 (because the previous addition increased by 6).

program 6:
package Numbers;

public class Series5 {

    public static void main(String[] args) {
        int no=22;
        int count=0;
        while(count<=5){
            System.out.print(8 +" ");
            System.out.print(no +" ");
            no=no+6;
            count=count+2;
        }
}
}
output:
8 
22 
8 
28 
8 
34 
Enter fullscreen mode Exit fullscreen mode

7.Look at this series: 21, 9, 21, 11, 21, 13, 21, ... What number should come next?

Let's analyze the pattern:

21 → 9 (subtract 12)
9 → 21 (add 12)
21 → 11 (subtract 10)
11 → 21 (add 10)
21 → 13 (subtract 8)

The pattern alternates between subtracting an even number and adding the same number.
The subtraction numbers decrease by 2 each time (12, 10, 8). Following this, the next subtraction should be by 6.
So, we subtract 6 from 13:

program 7:
package Numbers;

public class Series6 {

    public static void main(String[] args) {
        int no=9;
        int count=0;
        while(count<8) {
            System.out.println(21);
            System.out.println(no);
            no=no+2;
            count=count+2;
        }

    }

}
output:
21
9
21
11
21
13
21
15

Enter fullscreen mode Exit fullscreen mode

8.Look at this series: 5.2, 4.8, 4.4, 4, ... What number should come next?

Let's look at the pattern:
5.2 → 4.8 (subtract 0.4)
4.8 → 4.4 (subtract 0.4)
4.4 → 4 (subtract 0.4)

The pattern consistently subtracts 0.4.
Following this pattern, the next step would be to subtract 0.4 from 4:
4 - 0.4 = 3.6
So, the next number in the series is 3.6.

program 8:

public class Series7 {
    public static void main(String args[])
    {
    double no=5.2f;
    int count=0;
    while(count<6) {
        System.out.println(no);
        no=  no-0.4;
        count++;
    }
    }
}

output:
5.2
4.8
4.3999999999999995
3.9999999999999996
3.5999999999999996

Enter fullscreen mode Exit fullscreen mode

9.Look at this series: 2, 4, 6, 8, 10, ... What number should come next?

This is a simple series where each number is increasing by 2:
2 → 4 (add 2)
4 → 6 (add 2)
6 → 8 (add 2)
8 → 10 (add 2)
Following this pattern, the next step would be to add 2 to 10:

program:9

package Numbers;

public class Series9 {

    public static void main(String[] args) {
        int no=2;
        int count=1;
        while(count<=6) {
            System.out.println(no);
            no=no+2;
            count=count+1;
        }
    }

}

output:
2
4
6
8
10
12

Enter fullscreen mode Exit fullscreen mode

10.Look at this series: 31, 29, 24, 22, 17, ... What number should come next?

Let's look at the pattern in the series: 31, 29, 24, 22, 17.
31 to 29, the difference is -2.
29 to 24, the difference is -5.
24 to 22, the difference is -2.
22 to 17, the difference is -5.

It seems the pattern alternates between subtracting 2 and subtracting 5. If this pattern continues, the next step would be to subtract 2 from 17.

program 10:

package Numbers;

public class Series11 {

    public static void main(String[] args) {
        int no=31;
        int count=1;
        while(count<=5) {
            System.out.println(no);
            no=no-2;
            System.out.println(no);
            no=no-5;
        count=count+2;
    }

    }
}
output:
31
29
24
22
17
15

Enter fullscreen mode Exit fullscreen mode

Top comments (0)