Sunday, 20 May 2018

Number series

public class Series {

public static void main(String[] args) {

// Print 8 16 10 20 12 24 14 .. 10 elements of the series

int i = 8;
int j = 16;
int count = 0;
System.out.print("// Print 8 16 10 20 12 24 14 .. 10 elements of the series\n");
while (count<=9)
{
System.out.print(" "+i);
System.out.print(" "+j);
i = i+2;
j = j+4;
count++;
}

System.out.print("\n\n");
// Print 33 37 41 .. 10 elements of the series

int k = 33;
int counter = 0;

System.out.print("// Print 33 37 41 .. 10 elements of the series\n");
while (counter<=9)
{
System.out.print(" "+k);
k = k+4;
counter++;
}
}
}
Output:


No comments:

Post a Comment