nbaztec
Master KOD3R
The code is valid although logic is flawed. You should be returning `false` if `c>a+b || a>b+c || b>a+c`.Guys having trouble providing keyboard input as arguments to a function especially when passing more than 1 argument. Written a java code i procedural style ( without any use of objects) to show if a triangle can be formed when we provide three integer inputs.
The code works flawlessly when manually providing arguments to the method isTriangle.
But when using providing inputs through keyboard , it throws error. Providing the code below:
Code:import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class triangleFormation { public static boolean isTriangle (int a, int b, int c){ if (c>a+b || a>b+c || b>a+c ){ return true; } else{ return false; } } public static void main (String [] args)throws IOException { BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in)); String s = bufferedreader.readLine(); String r = bufferedreader.readLine(); String t = bufferedreader.readLine(); int m = Integer.parseInt(s); int n = Integer.parseInt(r); int o = Integer.parseInt(t); System.out.println("the triangle is " + isTriangle (m,n,o)); } }
I don't know if the process of providing keyboard input is correct or not. Only thing i found that its a hassle i java or i don't know some basic concepts. Providing inputs was so easy in c++.
Please throw some light into it guys.
How exactly are you providing input? You should input on separate lines.
And catch the exception within main itself. Ignoring it and letting the runtime deal with it (or rather not) is a bad practice.