It is aslo known as repetitive structure. Loop structure is used to run the block of codes until the condition is satisfied. While in execution, the if the condition is true then it is executed if the condition is false then the loop is terminated and follows the next statement of loop. Loop structure continue to execute until the condition is satisfied and it is very useful in many areas because of this feature. In java programming language, there are three options to use repetitive structure. 1) ' while ' statement 2)' do-while' statement 3)' for ' statement 1)'while' statement In while statement, certain code of block runs which is inside the while loop structure until the condition becomes false. After being the condition false, the loop will terminate itself. Syntax:- while(<condition expression>) { //program code } 2)'do-while ' statement It is also a type of statement. In this type of structure, while exp...
Scanner class is used to take input from the user in java. It has many different methods to handle other task too. To use Scanner class you have to use import java.util.Scanner; then you have to create an object of Scanner class. After creating an object, you can use the scanner object to store variables from user. When user gives input it stores in it and later on we can assign the value in variable for further use. let't see one example of Scanner class. Here, how to calculate Simple Interest is displayed. Source code... package oop; import java.util.Scanner; public class ScannerDemo { // Scanner is a class, located inside java.util package // Scanner is used to take input from user in console public static void main(String[] args) { int t; double p, r; double si; Scanner in = new Scanner(System.in); System.out.println("Principle amount:"); p = in.nextDouble(); System.out.println("Enter rate:"); r = in.nextDouble(); System.o...
Comments
Post a Comment