How to solve the series?
Ans:
2=1*1*1+1
9=2*2*2+1
28=3*3*3+1
65=4*4*4+1
Program in Java
import java.io.*; class Series { public static void main(String args[]) throws IOException { int n; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter no.of elements in series: "); n = Integer.parseInt(br.readLine()); if(n>0) { System.out.println("Series:"); for(int i=0; i<n; i++) { System.out.println("\t"+(int)(Math.pow(i,3)+1)); //Pattern for elements } } else System.out.println("You Entered the Wrong no."); } }
OUTPUT:
Enter no.of elements in series: 6 Series: 1 2 9 28 65 126