Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Norm

Thread: Re: Hello, im new to Java and need a little help

  1. #1
    siddy09 is offline Member
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Default 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

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Amok is offline Member
    Join Date
    Sep 2012
    Location
    Australia
    Posts
    12
    Rep Power
    0

    Default Re: Hello, im new to Java and need a little help

    Java 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");
    		}
    	}
    }

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default 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
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Amok is offline Member
    Join Date
    Sep 2012
    Location
    Australia
    Posts
    12
    Rep Power
    0

    Default 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

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default Re: Hello, im new to Java and need a little help

    Examples with descriptions are good.
    Posting solutions is not.
    DarrylBurke likes this.
    If you don't understand my response, don't ignore it, ask a question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •