Chapter 2 (Free web hosting services) Introduction to Java Applications 81 Common
Chapter 2 Introduction to Java Applications 81 Common Programming Error 2.11 It is a syntax error if the operators ==, !=, >=and<= contain spaces between their symbols, as in = =, ! =, > =and < =, respectively. Common Programming Error 2.12 Reversing the operators !=, >=and <=, as in =!, =>and =<, is a syntax error. Common Programming Error 2.13 Confusing the equality operator, ==, with the assignment operator, =, can be a logic error or a syntax error. The equality operator should be read as is equal to, and the assignment operator should be read as gets or gets the value of. Some people prefer to read the equality operator as double equals or equals equals. The next example uses six ifstructures to compare two numbers input into text fields by the user. If the condition in any of these ifstatements is true, the assignment statement associated with that if structure executes. The user inputs two values through input dialogs. Next, the program converts the input values to integers and stores them in variables number1 and number2. Then, the program compares the numbers and displays the results of the comparisons in an information dialog. The program and sample outputs are shown in Fig. 2.20. 1 // Fig. 2.20: Comparison.java 2 // Compare integers using if structures, relational operators 3 // and equality operators. 4 5 // Java extension packages 6 import javax.swing.JOptionPane; 7 8 public class Comparison { 9 10 // main method begins execution of Java application 11 public static void main( String args[] ) 12 { 13 String firstNumber; // first string entered by user 14 String secondNumber; // second string entered by user 15 String result; // a string containing the output 16 int number1; // first number to compare 17 int number2; // second number to compare 18 19 // read first number from user as a string 20 firstNumber = 21 JOptionPane.showInputDialog( "Enter first integer:" ); 22 23 // read second number from user as a string 24 secondNumber = 25 JOptionPane.showInputDialog( "Enter second integer:" ); 26 Fig. 2.20Using equality and relational operators (part 1 of 3). Fig. 2.20 Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01
Note: If you are looking for cheap webhost to host and run your apache application check Vision apache web hosting services