Home Answers Viewqa Java-Beginners java if statement

 
 


ratna rathor
java if statement
1 Answer(s)      a year ago
Posted in : Java Beginners

If statement in Java

View Answers

May 17, 2012 at 5:55 PM


if statement is used when you want to execute a block of code under any condition check. There is 4 kind of if block-

1.  Simple if Statement :
       if(test expression){
       ??.
       ?..
      }
2.   if-else statement:
      if(test expression){
       ??.
       ?..
      }
else{
?.
?
}
3.  Nested If .. else: you can also put another if with in if block.
if(test expression){
if(test expression){
          ??.
       ?..
    }
else{ 
          ??.
       ?..
   }
}
else{
          ??.
       ?..
}

4.  else if ladder:
      if(condition1){
       ?.
       }
        else if(condition2){
        ?.
       }
        else if(condition3){
         ?.
       }
       else {
       ?..
       }

Example:

   import java.util.Scanner;

   public class IfElse{
    public static void main(String [] args){
        int a=50,b;
        Scanner scanner=new Scanner(System.in);
        System.out.println("Input any number: ");
        b=scanner.nextInt();                      //input 
        if(a<b){
            System.out.println("a is less than b");
        }
        else{
            System.out.println("a is greater than b");

        }
    }
}

Description : For user input you can use Scanner object. It parses user input entered on the console or from a file. The work of Scanner is to break its input into separate tokens and then returns them one at a time.









Related Pages:
java if statement
java if statement  If statement in Java
switch statement
switch statement   i want to write a java program that computes Fibonacci,factorial,string reversal and ackerman using switch case to run as a single program
if else statement in java
if else statement in java  if else statement in java explain with example
JAVA statement - Java Beginners
JAVA statement  The import statement is always the first noncomment statement in a Java program file.Is it true?  Hi Friend, No,it is not true.If your class belongs to a package, the package statement should
The Switch statement
. To avoid this we can use Switch statements in Java. The switch statement is used... of a variable or expression. The switch statement in Java is the best way to test.... Here is the general form of switch statement: switch (expression){ case 1
if else statement in java
if else statement in java  explain about simple if else statement and complex if else statement in java with an example
Switch Statement
Switch Statement  How we can use switch case in java program ?  ... switches to statement by testing the value. import java.io.BufferedReader; import... switch case statement. The program displays the name of the days according to user
Java callable statement
Java callable statement  What is callable statement? Tell me the way to get the callable statement
conditional statement in java
conditional statement in java  Write a conditional statement in Java   Logical and comparison statements in OOPs are also know as conditional statements. You can learn "How to write conditional statement in Java " from
Java switch statement
Java switch statement  What restrictions are placed on the values of each case of a switch statement
GOTO Statement in java
GOTO Statement in java  I have tried many time to use java goto statement but it never works i search from youtube google but e the example on net are also give compile error. if possible please give me some code with example
'if' Statement - if inside if
Java Notes'if' Statement - if inside if if inside if You can put an if statement inside another if statement. Example -- series... the condition in an if statement, Java thinks it's finished with the body
ELSE STATEMENT!! - Java Beginners
ELSE STATEMENT!!  Hi! I just want to know why doesn't my else statement works? Else statement is there in the code below which is: else JOptionPane.showMessageDialog(null, n+ " is not in the array!");//doesn't work
if Statement - Overview
Java Notesif Statement - Overview Purpose The purpose of the if statement is to make decisions, and execute different parts of your program depending... with if. [The other 1% of the decisions use the switch/case statement
if Statement - Overview
Java Notesif Statement - Overview Purpose The purpose of the if statement... is a statement? A statement is a part of a Java program. We have already... directly after the condition in an if statement, Java thinks it's finished
Java IF statement problem
Java IF statement problem  Dear Sir/Madam i am using the following code. expected to not have any output but it still showing "welcome".. please help me why it showing "welcome". class c1 { int a=5; while(a>1
What is the difference between an if statement and a switch statement?
What is the difference between an if statement and a switch statement?   Hi, What is the difference between an if statement and a switch statement? Thanks,   Hi, The if statement gives options to select one option
What is the difference between a break statement and a continue statement?
statement? Thanks,   Hello, In Java programming language supports 3... and return statement etc. Other-then Java programming language the break...What is the difference between a break statement and a continue statement
If statement in java 7
If statement in java 7 This tutorial describes the if statement in java 7. This is one kind of decision making statement. There are various way to use if statement with else - If Statement :  If statement contains one boolean
Switch Statement in java 7
Switch Statement in java 7 This tutorial describes the if statement in java 7. This is one kind of decision making statement. Switch Statements : The switch statement is used when you want to test many statements based on some
While loop Statement.
While loop Statement.   How to Print Table In java using While Loop
Continue and break statement
statement in java program?   The continue statement restart the current loop whereas the break statement causes the control outside the loop. Here is an example of break and continue statement. Example - public class ContinueBreak
'if' Statement - Braces
Java Notes'if' Statement - Braces Braces { } not required for one statement If the true or false part of and if statement has only one... was expected. What is a statement? A statement is a part of a Java
'while' Statement
Java Notes'while' Statement Purpose - to repeat statements The purpose of the while statement is to repeat a group of Java statements many times. It's written just like an if statement, except that it uses
Java - Break statement in java
Java - Break statement in java       The java programming language supports the following types... statement is used in many programming languages such as c, c++, java etc. Some
Java Import Statement Cleanup - Java Tutorials
Java Import Statement Cleanup 2002-06-18 The Java Specialists' Newsletter [Issue 051] - Java Import Statement Cleanup Author: Dr. Cay S. Horstmann... to receive training in Design Patterns. Java Import Statement Cleanup
Break Statement in java 7
Break Statement in java 7 In this tutorial we will discuss about break statement in java 7. Break Statement : Java facilitate you to break the flow... java provides the way to do this by using labeled break statement. You can jump
Switch Statement example in Java
the switch statement. Here, you will learn how to use the switch statement in your java... the switch statement in Java. The following java program tells you for entering numbers... Switch Statement example in Java    
Java - Continue statement in Java
Java - Continue statement in Java       Continue: The continue statement is used in many programming languages such as C, C++, java etc. Sometimes we do not need to execute some
Continue Statement in java 7
Continue Statement in java 7 In this tutorial we will discuss about continue statement in java 7. Continue Statement : Sometimes you need to skip block... statement in loops. In java 7, Continue statement stops the current iteration
for statement
for statement  for(int i=0;i<5;i++); { system.out.println("The value of i is :"+i); } if i end for statement what will be the output   got the answer.. it displays only the last iteration that is "The value of i
Continue Statement
about Continue Statement click on the link http:/www.roseindia.net/java/beginners... Continue Statement       The continue statement occurs only inside the iterator statements like while
JDBC Prepared Statement Example
JDBC Prepared Statement Example       Prepared Statement is different from Statement object, When it is created ,it is represented as SQL statement. The advantage
Java Switch Statement
Java Switch Statement       In java, switch is one of the control statement which turns the normal flow... more about the switch statement click on:   http:/www.roseindia.net/java
Java Break Statement
Java Break Statement      ... is of unlabeled break statement in java. In the program break statement....           Syntax for Break Statement in Java
Break statement in java
Break statement in java Break statement in java is used to change the normal control flow of  compound statement like while, do-while , for. Break statement is used in many languages such  C, C++  etc. Sometimes it may
Writing a loop statement using Netbean
Writing a loop statement using Netbean  Write a loop program using NetBeans.   Java Loops class Loops{ public static void main(String[] args){ int sum=0; for(int i=1;i<=10;i
JDBC Prepared Statement Insert
JDBC Prepared Statement Insert   ... Statement Insert. In this Tutorial  the code describe the include a class... that enables you to communicate between front end application in java and database
count statement that saves results on a variable in a java bean
count statement that saves results on a variable in a java bean  ...; Statement statement = null; String SQLStr ; String retString...:3306/dev","root","anime"); statement = conn.createStatement
count statement that saves results on a variable in a java bean
count statement that saves results on a variable in a java bean  ...; Statement statement = null; String SQLStr ; String retString...:3306/dev","root","pro"); statement = conn.createStatement
Java Error In comapitable Type in statement - Java Beginners
Java Error In comapitable Type in statement  Here I want to Check...; //Statement st; faculty3() //constructor { j=new JFrame("faculty"); j1...; PreparedStatement st; //Statement st; faculty3(){ j=new JFrame("faculty
UNICODE or SQL statement issue - JDBC
UNICODE or SQL statement issue  Hi again............ I have got something new that........... i was using MS Access as the database with my JAVA Japplet.... In my applet i used JTextArea to display the output
For Loop Statement in java 7
For Loop Statement in java 7 In this section, we will discuss about for loop in java 7. This is one type of  loop statement. For Loop Statements : For loop is one way of looping to iterate block of code under certain condition
syntax error in SQL Insert Statement - Java Beginners
Access Driver] Syntax error in INSERT INTO statement. plz Help Me  Hi
The continue statement The continue statement is used in many programming languages such as C
The continue statement The continue statement is used in many programming languages such as C. The continue statement The continue statement is used in many programming languages such as C, C++, java etc. Sometimes we do not need
JDBC Prepared statement Close
JDBC Prepared statement Close       The Prepared statement interface extends from statement. An statement specify a precompiled SQL Statement. This specify a same object
Java error missing return statement
Java error missing return statement       Java error missing return statement are those error in Java that occurred when a programmer forget to write
Implementing Continue Statement In Java
Implementing Continue Statement In Java       In this Session you will learn how to use continue statement. First all of define class "Continue"
The try-with-resource Statement
The try-with-resource Statement In this section, you will learn about newly added try-with-resource statement in Java SE 7. The try-with-resource statement contains declaration of one or more resources. As you know, prior

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.