Arrays, Loops, Imports


Arrays, Loops, Imports

Import

Import

Java gives you the advantage of pre-built classes and methods that can perform many functions, The classes are grouped in packages that must be imported into your project if you want to use them.

For example, if you want to use the scanner methods, you will need to access the library by placing this line on top of your code:

import java.util.Scanner;

 

Loops

op

  1. For Loop
    We use for loops when you know exactly how many times you want to loop through a block of code. the syntax is:
    for (int i = 0; i < 5; i++) {
    System.out.println(i);
    }

 

  1. While Loop
    Loops can execute a block of code as long as a specified condition is reached. the syntax is:
    while (condition) {
    // code block to be executed
    }

 

For a detailed example, have a look at the dedicated post: Java While Loop.

  1. Do-While Loop
    It is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true. the syntax is:
    do {
    // code block to be executed
    }
    while (condition);

 

 


   

Get back to EMAM’S HOMEPAGE

I have created this page as a part of my project using Github, Please visit my profile, I will be more than happy to hear from you all.                       © Emam Shararah 2021