Statement IF & Relationships JAVA Operator

Statement IF & Relationships JAVA Operator

Decision (IF Statement) and Operator Relations

If statement in Java is used to compare an expression that returns true or false. Operators relationships that can be used are as follows:

operator relasi

Examples of program coding javanya if and relationships are as follows:
01import java.util.Scanner;
02public class IFdanRelasi{
03public static void main( String args[] ){
04Scanner input = new Scanner( System.in ); int n1;
05int n2;
06System.out.print"Input first integer number: " ); n1 = input.nextInt();
07System.out.print"Input second integer number: " ); n2 = input.nextInt();
08if ( n1 == n2 )
09System.out.printf( "%d == %d\n", n1, n2 ); if ( n1 != n2 )
10System.out.printf( "%d != %d\n", n1, n2 ); if ( n1 < n2 )
11System.out.printf( "%d < %d\n", n1, n2 ); if ( n1 > n2 )
12System.out.printf( "%d > %d\n", n1, n2 ); if ( n1 <= n2 )
13System.out.printf( "%d <= %d\n", n1, n2 ); if ( n1 >= n2 )
14System.out.printf( "%d >= %d\n", n1, n2 );
15}
16}

if and relasi java
the results of coding, in the example I enter the first number 2 and the second number 3 to be compared with the relation, visible results of the relation with the condition if fulfilled will be executed and display,  2! = 3 (two does not equal three) 2 <= 3 (two less than and equal to 3), 2 <3 (two less than three).


Berlangganan update artikel terbaru via email:

0 Response to "Statement IF & Relationships JAVA Operator"

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel