Create a directory named esc101-lab03and put all your
java classes within that directory.
There are four problems in this lab. Do not use any
library function. Use of conditional statements is not allowed.
Write a Java class with a main method that declares and initializes a character variable. It prints true if the character corresponds to a digit i.e. one of 0, 1, 2, ..., 9; otherwise it prints false. Extend the program to check if it is an alphabet (i.e. one of a, b, ..., z or A, B, ..., Z) or a digit. Such characters are called alphanumerics.
Write a Java class with a main method
that declares an integer and initializes it to a five-digit number. It
prints the sum of the digits of the integer. Extend the program to check if
the number is divisible by 11. For this purpose you should check the
divisibility in two ways. Suppose the number is 12345. The program should
print the following three lines.
Sum of digits of 12345 is 15.
When divided by 11, 12345 leaves
remainder 3.
The alternate digit sums of 12345 are
9 and 6. Divisibility by 11: false.
The third line is generated by using the standard divisibility test of 11
where you compute the sums of the alternate digits. The number is divisible
by 11 iff the difference of the sums is divisible by 11.
Write a Java class with a main method
that declares a double number and initializes it a positive real number. The
program prints the integer part, fractional part, and the nearest integer of
this number. Assume that the nearest integer of X.5 is X+1 where X is a
non-negative integer. For example, if the number is 4.678 the program should
produce the following output.
The integer part of 4.678 is 4.
The fractional part of 4.678 is
0.678.
The nearest integer to 4.678 is 5.
Write a Java class with a main method that declares an integer and
initializes it to a four digit number. The program prints true if it is a
palindrome; otherwise it prints false. A palindrome is a number which when
read in the reverse direction is the same as the original number. For
example, 1771 is a palindrome.
sample output:
The number is 1771. Palindrome test:
true.
Hint: try to make use of the solution to the 2nd problem.