Results 1 to 3 of 3
  1. #1
    blessed07 is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default Confused between the usage of printf and println... and ternary operator

    the following code is not correct, can someone pls tell me what are the mistakes?

    import static javax.swing.JOptionPane.*;
    public class Count {
    public static void main (String args []) {
    int a = Integer.parseInt(showInputDialog(
    "Enter a number."));

    String b = a < 100 ? "smaller" : "bigger";
    System.out.printf("String b %s, Integer a %d", int a, String b );
    }
    }


    How to determine the output? To my knowledge, it should be the operator evaluates the first argument and, if true, evaluates the second argument. If the first argument evaluates to false, then the third argument is evaluated.
    Then I will get true, true, true. Pls explain to me why I am wrong. Thanks

    public class BooleanEx1 {

    static String m1(boolean b) {
    return b ? "T" : "F";
    }
    public static void main(String[] args) {
    boolean t1 = false ? false : true ? false : true ? false : true;
    boolean t2 = false ? false
    : (true ? false : (true ? false : true));
    boolean t3 = ((false ? false : true) ? false : true) ? false
    : true;
    System.out.println(m1(t1) + m1(t2) + m1(t3));
    }
    }

  2. #2
    soccer_kid_6 is offline Member
    Join Date
    Feb 2010
    Posts
    35
    Rep Power
    0

    Default

    What are you attempting to do anyway?

  3. #3
    blessed07 is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Smile Just to practice

    I am trying to practice and know more about the tools. Could u pls help to explain?

Similar Threads

  1. Few errors with for loop/printf
    By ks1615 in forum New To Java
    Replies: 8
    Last Post: 03-12-2009, 10:47 PM
  2. Printf error
    By ks1615 in forum New To Java
    Replies: 4
    Last Post: 03-10-2009, 07:59 AM
  3. difference between system.out.println() & out.println()
    By wickedrahul9 in forum Advanced Java
    Replies: 5
    Last Post: 10-19-2008, 12:06 AM
  4. Demonstration of printf() method
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 08:37 PM
  5. printf
    By Jack in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 05:31 AM

Posting Permissions

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