Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Conditional Operator "?:" not compiling

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Sneaky
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Conditional Operator "?:" not compiling

    // Practical 7A (Revision) - Q
    // Marcus Ward
    // 26/10/2011
    /* User will enter a number, and using the conditional  
    operator "?:" the program will display if pos. or neg. */
     
    import java.util.Scanner;
     
    public class PositiveOrNegativeNumber
    {  
       public static void main(String[] args)
    	{
    	Scanner keyboardIn = new Scanner(System.in);
     
    	// declare variables
    	int digit;
     
    	// get user input
    	System.out.print("Enter a number: ");
    	digit = keyboardIn.nextInt();
     
    	System.out.println(digit>=0?"The number is positive":"The number is negative");
     
    	}
    }
    Last edited by mwardjava92; October 30th, 2011 at 10:23 AM.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Conditional Operator "?:" not compiling

    Hi mwardjava92. Welcome to Java Programming Forums.

    What compilation errors do you get?

    This code works perfectly for me, you will need to provide a full explanation of the problem and include error outputs, we cannot fly blind.

    Regards,
    Chris

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    50
    My Mood
    Fine
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Conditional Operator "?:" not compiling

    Works fine for me too ...

    application context
    Last edited by daniel.j2ee; December 13th, 2011 at 04:58 PM.

  4. #4
    Member
    Join Date
    Oct 2011
    Posts
    40
    My Mood
    Sneaky
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Re: Conditional Operator "?:" not compiling

    Hi all,
    Thanks for the replies. It was only an error in the installaton on jGrasp was the problem.
    Forgive me as I'm only a beginner.

    Regards.
    mwardjava92

Similar Threads

  1. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  2. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  3. Java says:"Hello World". I say:"It works!"
    By Davidovic in forum Member Introductions
    Replies: 4
    Last Post: June 29th, 2010, 07:13 AM
  4. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM
  5. Replies: 4
    Last Post: August 13th, 2009, 05:54 AM