Java Program: How to Use If Statement in Java Programming

Java Program: How to Use If Statement in Java Programming

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.

Head First Java, 2nd Edition, Kathy Sierra, Bert Bates, Sierra Kathy, Bates Be
Current Bid: $19.14
Data Structures and Algorithm Analysis in Java by Mark A. Weiss 3rd ,3e 3ed
Current Bid: $46.48

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:

Java Related Tutorials:

Java Tutorial Examples
Java Tutorial for Beginners: A Beginners Guide on Learning Java Programming
Java Simple Codes for Beginners
How to Program in Java Using Netbeans: Complete Simple Easy Steps
Basic Knowledge Required in Programming
5 Important Tips to Learn Java Programming and Other Programming Languages

Other Java Source Code Samples:

Java Program: Palindrome Test Java Source Code
Java Program: Using Multi If and Else Statement in Java Programming
Java Program: Reverse String in Java Using For Loop
Java Program: Count the Number of String Characters in Java
Java Program: How to Parse a String into Integer in Java Programming
Java Program: How to Use If Statement in Java Programming
Java Program: How to Use Switch Statement in Java
Class in Java: Learn More about Java Classes with Sample Java Codes
Java Source Code: Sort Numbers in Selection Sort
Java Source Code Recursion: Recursive Koch Snow Flakes
Java Source code on Printing the Greatest Common Divisor (GCD) using Recursion
Java Source code: Reverse String in Java Using Recursion
Java Source code: How to Add numbers inside an Array Using Recursion
Java Source Code in a Recursive Linear Search
Java Source Code: A Recursive Asterisk Diamond Shape Program
Java Code Sample: Sort Numbers in Bubble Sort
Java Source Code Determine Person’s Salutation and Current Age
Java source code in Recursive function for X to the power Y
Java Source Code: Binary Search in Recursion
Java Source code sample: How to Add Numbers inside an Array using For Loop
Java source code Sample: Print Different Asterisk Shapes in Recursion