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...
To understand the Class and Object in java, first you simply you imagine the real world. Suppose you have a house. In house we stay, before we stay we build a house. Before we build house, we design it. We make a sketch or blue print of that house. In that sketch we determine structure of house in form of architectural drawing. We all know that we can't stay in that architectural drawing. We have to built a house to stay in it. Here, class is like a sketch and the object is house. \ A class is like the architectural drawing of a house from which the house object is built. Just as you can’t stay in an architectural drawing of a house, you cannot ‘stay’ in a class. Just as someone has to build a house from its architectural drawing before you can actually stay in it, you must build an object of a class before you can get a program to perform the tasks defined in the class. In a housing estate, there are many houses built from the same architectural design. ...
/* Write a program in Java that takes two integer input from user then add them both and displays the output.*/ import java.util.Scanner; //program uses class scanner public class Calculator{ public static void main(String[ ] args) { int ,a,b,total; //create an Scanner object to read input from user. Scanner input =new Scanner(System.in); System.out.println("Enter first number:"); a=input.nextInt(); //read first number System.out.println("Enter second number:"); b=input.nextI...
Comments
Post a Comment