Hi everyone :-)
Maybe I have over done it, I have not find a splice function in java...
I am not sure why my code fails...
It gives the correct answers when I try it.
5, 3, 2 => exists
0 for a side => exists
5, 2, 2 => exists
package com.codegym.task.task04.task0415;
/*
Rule of the triangle
*/
import java.io.*;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
Integer[] a = new Integer[3];
Scanner sc = new Scanner(System.in);
a[0] = sc.nextInt();
a[1] = sc.nextInt();
a[2] = sc.nextInt();
Boolean canExist = false;
for (int i = 0; i < a.length; i++) {
Integer[] b = new Integer[a.length];
int sidesSum = 0;
if (a[i] == 0) break;
//splice function equivalent
for (int j = 0; j < a.length; j++) {
if (a[i] != a[j]) b[j] = a[j];
else b[j] = 0;
sidesSum += b[j];
// System.out.print(a[i] + "?" +sidesSum + " ");
}
// System.out.println(a[i]);
if (a[i] > sidesSum) {
canExist = false;
break;
}
if (a[i] < sidesSum) {
canExist = true;
}
}
if (canExist) System.out.println("The triangle is possible.");
else System.out.println("The triangle is not possible.");
}
}