Re: Hello, im new to Java and need a little help
im working on this problem now and im honestly completely clueless on how to do it, can someone help me please? i need to write a program that takes three positive integers as command-line arguments and prints true if any one of them is greater than or equal to the sum of the other two and false otherwise which isbasically testing if they can be the sides of a triangle
Re: Hello, im new to Java and need a little help
Post moved to own thread.
Start by writing code to define a class and a main method.
Have the main() method print out the contents of the String array that is passed to it.
When that works, move to the next step.
Re: Hello, im new to Java and need a little help
Code:
public class Greater
{
private static final int SIZE = 3;
public static void main(String[] args)
{
if(args.length != SIZE)
{
System.err.println("Invalid number of arguments....");
System.exit(0);
}
int numberArray[] = new int[SIZE];
for(int i = 0; i < SIZE; i++)
{
try
{
numberArray[i] = Integer.parseInt(args[i]);
}
catch(Exception e)
{
System.err.println("Argument you entered was not digit.....");
System.exit(0);
}
}
if((numberArray[0] >= (numberArray[1] + numberArray[2])) || (numberArray[1] >= (numberArray[0] + numberArray[2]))
|| (numberArray[2] >= (numberArray[0] + numberArray[1])))
{
System.out.println("True");
}
else
{
System.out.println("false");
}
}
}
Re: Hello, im new to Java and need a little help
@amok Don't spoonfeed code. The idea is to help the OP learn how to solve problems. Posting code with no comments describing how the solution to the problem was found is not a good way to help the OP learn.
See: The Problem with Spoon-feeding
Re: Hello, im new to Java and need a little help
ok Norm i will keep that in mind. When i was learning programming, i learned by looking at examples, sometime i would not understand even when people will try to explain me but as soon as i see the example it was very clear to me. But tats just me..........
From next time i will just give them hints rather than solution....i have posted other codes as well, so just ignore them...
Thanks
Re: Hello, im new to Java and need a little help
Examples with descriptions are good.
Posting solutions is not.