ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming»
  • Programming Languages

Java Program: How to Use If Statement in Java Programming

Updated on January 30, 2013

How to use If Statement in Java Programming with Free Java Source Code of Vehicle Identifier

The if statement in Java is basically means if(this condition meets){implement this code}, hence the syntax of if statement in Java Programming is this:



Write your code hereā€¦.


If statement in Java is usually use to meet the other requirements that need to be done by the program.For example, in identifying the vehicles, we will have an algorithm, if the vehicle has 4 wheels, that program will say that it is a car, if it has 3 wheels, it would be say a tricycle, and if it has 2 wheels it would say a motorcycle.

This program is just simple, however it would help you much to understand when should you use if statement if you are making a certain program.

Example Free Source Code of Vehicle Identifier

Package name: Vehicle Identifier

package vehicle_identifier;

import java.util.Scanner;

public class Main {

    public static void main(String[] args)
        Scanner input = new Scanner(;

        System.out.print("Enter the number of your Vehicle's Wheels: ");
        int vehicles_wheels = input.nextInt();

        if(vehicles_wheels == 4)
            System.out.print("You have a Car.");
        if(vehicles_wheels == 3)
            System.out.print("You have a Tricycle.");
         if(vehicles_wheels == 2)
            System.out.print("You have a Motorcycle.");


Sample Output:


    0 of 8192 characters used
    Post Comment

    • profile image

      Ahmad 4 years ago

      thanks Aisha iam totaly newbie