Computer Science, asked by schoolstudent, 1 year ago

Write a program in JAVA to check whether a series belongs to PseudoArithmetic sequence.
The logic is :
Sequence of n integers : 2, 5, 6, 8, 9, 12 We observe that 2 + 12 = 5 + 9 = 6 +8 = 14

The sum of the above sequence can be calculated as 14 x 3 = 42

For sequence containing an odd number of elements the rule is to double the middle element, for example 2, 5, 7, 9, 12

=2 +12 = 5 +9 = 7 +7 = 14

14 x 3 = 42 [ middle element = 7]


schoolstudent: pseudo arithmetic sequence is a series of integers in an order where the sum of the pairs of elements at equidistance from front and end remain same.
nitish8089: would sequence is user defined.. or the same one..
schoolstudent: sequence is user defined
nitish8089: now you give correct definition...
schoolstudent: can no one answer this question??
nitish8089: hey i am answer always but program and logic took some time too think.

Answers

Answered by nitish8089
12

code \: is \: ready................check \: out \: \\  bug \: if \: you \: see \: out \: tell \: me \: in \: \\ comment
 =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  =  = =
import java.util.Scanner;

public class Program

{
public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

int []a=new int[n];

System.out.println("enter the sequence values");

for(int i=0;i<n;i++){

a[i]=sc.nextInt();

}

int sum=a[0]+a[(a.length-1)];

if(n%2==0){

int c=0;

for(int i=0;i<n/2;i++){

int temp_sum=a[i]+a[(a.length-1)-i];

if(temp_sum==sum)

continue;

else{

System.out.println("not a pesudo arithemitic sequence");

c++;

}

break;

}

if(c==0)

System.out.println("sum of pesudo arithmetic number is:" +(sum*(n/2)));

}

else{

int c=0;

for(int i=0;i<n/2;i++){

int temp_sum1;

if(i!=(n/2)+1){

temp_sum1=a[i]+a[(a.length-1)-i];}

else{

a[(a.length-1)-i]=a[i];

temp_sum1=a[i]+a[(a.length-1)-i];

}

if(temp_sum1==sum)

continue;

else{

System.out.println("not a pesudo arithemitic sequence");

c++;

}

break;

}

if(c==0)

System.out.println("sum of pesudo arithmetic number is:" +(sum*((n/2)+1)));

}

}
}
Answered by nikhilghodke0202
0

what is the output of this program

Similar questions