Hopefully I attached my code snippet, Whats wrong in my code. Can anyone please give a solution with explanation ?
package com.codegym.task.task04.task0424;
/*
Three numbers
*/
import java.io.*;
import java.util.Scanner;
public class Solution {
public static int findIndex(int arr[], int t)
{
int j =0;
while(j<arr.length)
{
if(arr[j] == t)
return j+1;
else
return j = j +1;
}
return -1;
}
public static void main(String[] args) throws Exception {
//write your code here
Scanner sc = new Scanner(System.in);
int a[] = new int[3];
for(int i=0;i<3;i++)
{
a[i] = sc.nextInt();
}
int i =0;
if(a[i] == a[i+1] && a[i] != a[i+2])
{
System.out.println(findIndex(a,a[i+2]));
}
else if(a[i+1] == a[i+2] && a[i+1] != a[i])
{
System.out.println(findIndex(a,a[i]));
}
else if(a[i+2] == a[i] && a[i+2] != a[i+1])
{
System.out.println(findIndex(a,a[i+1]));
}
}
}