Home »
Posts tagged "Learn Fundamentals of Java" (Page 3)
Arrays Previously you learned about variables that are place holders for a single value. Arrays are variables that can hold more than one value, they can hold a list of values of the same type. For example, to store the marks of a student, we used a variable: double marks_obtained = 346; To store the marks of another student, we changed the variable marks_obtained. marks_obtained = 144; By changing marks_obtained, we...
Continue reading »
February 29, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
The for statement The for loop is the most widely used Java loop construct. The structure of the Java for statement is as below: for (counter = initial_value ; test_condition ; increment/decrement counter) { statements } Semicolons separate the three parts of a for loop: 1. The initial_value initializes the value of the loop counter. 2. The test_condition tests whether the loop should be executed again. The loop is exited when...
Continue reading »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
The do while statement The do while statement evaluates the test after executing the body of a loop. The structure of the Java do-while statement is as below: do { statements } while (expression); Let us write the same program to print the squares of numbers from 1 to 5. This time we will use a do-while loop. The following steps need to be performed. 1. Initialize number = 1 2....
Continue reading »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
The while statement The while statement evaluates the test before executing the body of a loop. The structure of the Java while statement is as below: while (expression) { statements } Let us write a program to print the squares of numbers from 1 to 5. The following steps need to be performed. 1. Initialize number = 1 2. Test if the number <= 5 3. If yes, print the square...
Continue reading »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
Repetition Structures In real life you often do something repeatedly, for example, consider a task such as reading a book, first you open the book, and then repeatedly – read a page; flip the page – until you get to the end of the book, then close the book. Similarly, when writing programs, you might need to perform the same sequence of statements repeatedly until some condition is met. The ability...
Continue reading »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
The switch Statement The switch statement is used to execute a block of code matching one value out of many possible values. The structure of the Java switch statement is as below: switch (expression) { case constant_1 : statements; break; case constant_2 : statements; break; … … default : statements; break; } Within the switch statement, as you can see, there can be many case statements. The expression is compared with...
Continue reading »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
The if else Statement The if statement in Java lets us execute a block of code depending upon whether an expression evaluates to true or false. The structure of the Java if statement is as below: if (expression) { statements } The expression given in the round brackets after the if keyword, is a condition – an expression constructed using relational and logical operators. If the condition evaluates to true, the...
Continue reading »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
Selection Structures In real life, you often select your actions based on whether a condition is true or not. For example, if it is raining outside, you carry an umbrella, otherwise not. Similarly in a program, you may want to execute a part of the program based on the value of an expression. Java provides two statements – the if else statement and the switch statement for executing a block of...
Continue reading »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
Page 3 of 4« Prev
1
2
3
4
Next »