Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Can someone help me how to pass the argument i really need to understand properly.Give me a explained answer

Write a program TestDemo.java, which accepts the number as argument and print “You Have Entered Zero” if the value is equal to 0 along with the ASCII value of the number. It should print “You Have Entered Positive Value” if the value is greater than 0 along with the ASCII value. It should print “You Have Entered Negative Value” if the value is less than 0 along with the ASCII value

1 Answer

You could just make a method that accepts a number for you to test:

public void testNumber(int number) {
    if (number == 0) {
    System.out.println("The number is Zero"); // Number must be zero
    } else if (number > 0 ){
    System.out.println("The number is Positive"); // Number greater than zero so must be positive
    } else {
    System.out.println("The number is Negative"); // Number less than zero so must be negative
    }
}

So to call this method in your Main method you can just type-> testNumber(with your number in here);

testNumber(0); //  Prints: The number is Zero
testNumber(1);  // Prints: The number is Positive
testNumber(-1); // Prints: The number is Negative