Hi,
I am getting WA for the problem What’s next - the problem in which we’ll find whether a series is AP or GP.
Please have a look at my code and correct me where I’m wrong.
import java.util.;
import java.lang.;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int[] a = new int[3];
for(int i=0; i<3; i++)
{
a[i] = sc.nextInt();
}
System.out.println(“0 0 0”);
if(a[2]-a[1] == a[1]-a[0] && a[2]-a[1] != 0)
{
int d = a[2]-a[1];
System.out.println("AP " + (a[2]+d));
}
else if(a[1]*a[1] == a[0]*a[2])
{
if(Math.abs(a[2]) > Math.abs(a[1]))
{
int p = a[2]/a[1];
System.out.println("GP " + (a[2]*p));
}
else
{
int p = a[1]/a[2];
System.out.println("GP " + (a[2]/p));
}
}
}
}
created
last reply
- 8
replies
- 622
views
- 2
users
- 2
links