ICSE - JAVA Series Programs :
² Display the following Series up to 10 terms
(a) 1, 4, 9, 16 ..... 10 term
class Series
{
public static void main(String args[])
{
for (int i = 1; i <= 10; i++)
{
System.out.print(i * i + " ");
}
}
}
(b) 1, 2, 4, 7, 11 ..... 10 term
class Series
{
public static void main(String args[])
{
int i, a=1;
for (i = 1; i <=10; i++)
{
System.out.print(a + " ");
a=a+i;
}
}
}
(c) 3, 6, 9, 12 ..... 10 term
class Series{
public static void main(String args[])
{
int i;
for (i = 1; i <= 10; i++)
{
System.out.print((i*3) + " ");
}
}
}
(d) 4, 8, 16, 32 .... 10 term
class Series{
public static void main(String args[])
{
for (int i = 2; i <= 11; i++)
{
System.out.print((int)(Math.pow(2, i)) + " ");
}
}
}
(e) 1.5, 3.0, 4.5, 6.0 .... 10 term
class Series{
public static void main(String args[])
{
float a = 1.5f;
for (int i = 1; i <= 10; i++)
{
System.out.print(a + " ");
a+= 1.5f;
}
}
}
(f) 0, 7, 26 ..... 10 term
class Series{
public static void main(String args[])
{
for (int i = 1; i <= 10; i++)
{
int a = (int)(Math.pow(i, 3) - 1);
System.out.print(a + " ");
}
}
}
(g) 1, 9, 25, 49 .... 10 term
class Series{
public static void main(String args[])
{
for (int i = 1; i <= 19; i = i + 2)
{
System.out.print((i * i) + " ");
}
}
}
(h) 4, 16, 36, 64 ..... 10 term
class Series{
public static void main(String args[])
{
for (int i = 2; i <= 20; i = i + 2)
{
System.out.print((i * i) + " ");
}
}
}
(i) 0, 3, 8, 15 .... 10 term
class Series{
public static void main(String args[])
{
for (int i = 1; i <= 10; i++)
{
System.out.print((i * i - 1) + " ");
}
}
}
(j) 24, 99, 224, 399 ... 10 term
class Series{
public static void main(String args[])
{
for (int i = 5; i <= 50; i = i + 5)
{
int a = (int)(Math.pow(i, 2) - 1);
System.out.print(a + " ");
}
}
}
(k) 2, 5, 10, 17 .... 10 term
class Series{
public static void main(String args[])
{
for (int i = 1; i <= 10; i++)
{
System.out.print((i * i + 1) + " ");
}
}
}
No comments