I have this work that I have tried, but when I enter 1, then it does not give any output Because 1 is> 0 and 1 is also not, but I still get the output:
Enter a + ve number 1 You entered 1 to ask for a + ve number: )
.
import java.util.Scanner; Class main {public static zero main (string [] args) {scanner input = new scanner (System.in); System.out.println ("Enter a + ve number"); Int number = input.nextInt (); System.out.println ("You entered" + number); If (number> gt; 0) if (number% 2 == 0) is System.out.println ("number" + number + "plus"); Else System.out.println ("I had asked for a + ve number :)"); }}
Your second actually 2 If
no 1 if
indentation is not in the form of a show.
if (cond1) if (cond2) else // This is second 2 if not 1, if
is the same:
if (cond1) {if (cond2) {} else {}}
The reason for this is that Java grammar says a And the closest is unmatched if it can possibly be .
If you want to match the first time with another, if you need to use parentheses:
if (cond1) {if ( Cond2) {}} else {}
Comments
Post a Comment