package com.codegym.task.task04.task0424;
/*
Three numbers
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
boolean check=false;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int a[] = new int[3];
for (int i = 0; i < 3; i++)
a[i] = Integer.parseInt(reader.readLine());
int currentValue = a[0];
int smallestIndex = 0;
for (int j=1; j < 3; j++) {
if (a[j] < currentValue) {
currentValue = a[j];
smallestIndex = j;
}
}
for(int i=1;i<3;i++){
if(a[i-1]==a[i]){
check=true;
break;
}
}
smallestIndex = smallestIndex+1;
if(check)
System.out.println(smallestIndex);
}
}
whats wrong in my code....
it shows one error "The program should display the index of the number that is different from the others."how to solve this?
Resolved
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Arjun Kiruthivasan
12 August 2018, 17:18
yes but it shows error
0
Pavlo Plynko Java Developer at CodeGym
12 August 2018, 17:22solution
1, 1, 2 - expected output: 3
1, 2, 1 - expected output: 2
2, 1, 1 - expected output: 1
+2
WatWat
8 October 2018, 04:38
The indices start at 0
0
Pavlo Plynko Java Developer at CodeGym
12 August 2018, 14:28
Have you tested your solution with different combinations?
1 1 2
1 2 1
2 1 1
0