Java Help


#1

I wanted to know why does this java program print out
@@@@
$$$$

instead of just
@@@@

public class JavaApplication169 {

    public static void main(String[] args) {
     int x = 5, y = 8;

      if (y == 8)
       {
         if (x == 5)
            System.out.println("@@@@");
         else
            System.out.println("&&&&");
            System.out.println("$$$$");  
       }  
    }


    }

run:
@@@@
$$$$

#2

Use brackets inside if “If else case” code line more than 2.

Assume x = 5

    if (x == 5)
        System.out.println("@@@@"); <-- printed 
     else
        System.out.println("&&&&"); <-- not printed, case not match
        System.out.println("$$$$");  <-- printed, due to "If Else" case are not affected this line.

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.