Skip to content

Instantly share code, notes, and snippets.

  • Select an option

  • Save Pyroarsonist/60c35cf55b256ef336fb to your computer and use it in GitHub Desktop.

Select an option

Save Pyroarsonist/60c35cf55b256ef336fb to your computer and use it in GitHub Desktop.
Lesson5lvl2a
package lvl2a;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int []A=new int [5];
System.out.println("Input sequence of 5 values : ");
for (int i=0;i<A.length;i++) {
A[i]=sc.nextInt();
}
System.out.println("Next is : "+sequence(A));
sc.close();
}
static String sequence (int A[]) {
String z="Error!";
int x=A[4];
int c=0;
if (A[4]%5==0&&A[3]%4==0&&A[2]%3==0&&A[1]%2==0&&A[0]%1==0) {
for (; ;) {
x/=5;
c++;
if (x==1) {
break;
}
}
z=Double.toString(Math.pow(6,c));
}
else if ((A[4]-A[3])==(A[3]-A[2])&&(A[3]-A[2])==(A[2]-A[1])&&(A[2]-A[1])==A[1]-A[0]) {
z=Integer.toString(2*A[4]-A[3]);
}
else if ((A[4]/A[3])==(A[3]/A[2])&&(A[3]/A[2])==(A[3]/A[2])&&(A[2]/A[1])==(A[1]/A[0])) {
z=Integer.toString(A[4]*A[4]/A[3]);
}
return z;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment