Home »
Archive by category "Online Computer Education" (Page 5)
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
Control Flow Recall, that a program is nothing but a sequence of instructions. Java executes the instructions in sequential order, that is, one after the other. However, sometimes you might want to execute an instruction only if a condition holds true. Or you may want to execute a set of instructions repeatedly until a condition is met. Java provides selection structures for the former and repetition structures for the latter.
Continue reading »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
Operators Operators are special symbols in a programming language and perform certain specific operations. You have already seen two operator * and /. Table 2 lists the Java Arithmetic operators, Table 3 lists the Relational operators, Table 4 lists the Assignment operators, and Table 5 lists the Logical operators available in Java. Java also provides Bitwise operators which are beyond the scope of this text.
Continue reading »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
String Variables In the Percentage Calculator program of the previous section, we used variables to store numeric data. Quite often we want variables to store textual data, for example, the name of a student. A variable of the primitive data type char can be used to store a single character. To assign a value to a char variable we enclose the character between single quotes. char middle_name = ‘M’; To store...
Continue reading »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
Primitive Data Types Besides the two Java data types (int, double) that you have seen in the percentage calculator program, we can use six more data types. In all, Java supports eight primitive data types as in Table 1. STYLE TIP – Variable Names 1. Variable names can begin with either an alphabetic character, an underscore (_), or a dollar sign ($). However, convention is to begin a variable name with...
Continue reading »
February 27, 2016 evirtualguru_ajaygourOnline Computer EducationNo Comment
Page 5 of 13« Prev
1
2
3
4
5
6
7
8
…
13
Next »