138 Control (Zeus web server) Structures: Part 1 Chapter 4 by
138 Control Structures: Part 1 Chapter 4 by the placement of braces ({}). On first glance, the programmer may not be sure which if and elsematch; this is referred to as the dangling-else problem. We have eliminated the indentation from the following code to make the problem more challenging. (Hint: Apply indentation conventions that you have learned.) a) if ( x < 10 ) if ( y > 10 ) Console.WriteLine( “*****” ); else Console.WriteLine( “#####” ); Console.WriteLine( “$$$$$” ); b) if ( x < 10 ) { if ( y > 10 ) Console.WriteLine( “*****” ); } else { Console.WriteLine( “#####” ); Console.WriteLine( “$$$$$” ); } 4.14 A palindrome is a number or a text phrase that reads the same backwards as forwards. For example, each of the following five-digit integers are palindromes: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it is a palindrome. If the number is not five digits, display an error message dialog indicating the problem to the user. When the user dismisses the error dialog, allow the user to enter a new value. 4.15 A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All their data are transmitted as four-digit integers. They have asked you to write a program that will encrypt their data so that it may be transmitted more securely. Your application should read a four-digit integer entered by the user in an input dialog and encrypt it as follows: Replace each digit by (the sum of that digit plus 7) modulus 10. Then swap the first digit with the third, and swap the second digit with the fourth. Print the encrypted integer. Write a separate application that inputs an encrypted four-digit integer and decrypts it to form the original number. 4.16 The factorial of a nonnegative integer n is written n! (pronounced n factorial ) and is defined as follows: n! = n (n - 1) (n -2) … 1 (for values of n greater than or equal to 1) and n! = 1 (for n = 0). For example, 5! =5 4 3 2 1, which is 120. a) Write an application that reads a nonnegative integer from an input dialog and computes and prints its factorial. b) Write an application that estimates the value of the mathematical constant e by using the formula 111 e = 1+—- –+—- –+—–+ 1! 2! 3! c) Write an application that computes the value of ex by using the formula 23 x xxx e = 1+—–+—- —+—- –+ 1! 2! 3!
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision j2ee hosting services