If Else Condition with Java program

If else Condition with Java Program

If Else condition with java program is very basic concepts of language. Today we will introduce this basic condition with Scanner class [From java.util.* package] and Static method. We all know very well about simple if else condition in C and Cpp. So we will focus on other two concepts.

Static Method: : condition with java program

Generally static keyword uses with static variable and method. Currently we will only focus on static method in main class. When we use static method in main class, we do not need any object for calling a static method. So this is very important thing about static method. We will see use of static method in our video or static program.

Scanner Class : condition with java program  

We already know about command line argument in out last blogs. Now we use another method for run time value. Using of Scanner Class we can easy insert value in run time. For this class, we have to import java.util.* package in our program’s first line.

 

Program in If Else condition with Scanner Class and Static Method.

Import java.util.*;

class condition1

{

static void findMax(int x, int y) // Static method

{

if(x>y)

{

System.out.println(“X is Max”);

}

else

{

System.out.println(“Y is Max”);

}

}

public static void main(String args[])

{

Scanner in1 = new Scanner(System.in);

int x,y;

System.out.print(“Enter X : ”);

x = in1.nextInt(); // Method

System.out.print(“Enter Y : ”);

y = in1.nextInt();  // Method

findMax(x,y);        // Calling

}

}

Output:

Enter X : 45

Enter Y : 34

X is Max

 

Video available on YouTube.

 

 

If you have problem on this blog, you can directly comment or free subscribe on website.

 

Free Download | Free Video

 


 

1366total visits,10visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

Enter Captcha Here :*

Reload Image