This time I will share about the assignment that has
given. We are required to declare and manipulate strings and character using
methods provided by Character and String class. Here I include all of the tasks
that I have done.
1. a. System.out.printf( “%6b”, ( 1 > 2 ) );
b. System.out.printf( “%6s\n”, “Java”);
c. System.out.printf(“Amount is %f %e”, 32.32, 32.32);
d. System.out.printf(“%8d%8.1f”, 1234, 5.6321);
e. System.out.printf(“%-8d%-8.1f”, 1234, 5.6321);
2. String s1 = “Welcome to Java”;
String s2 = “Welcome to Java”;
String s3 = new String(“Welcome to Java”);
System.out.println( s1 == s2);
System.out.println( s1 == s3);
3. Write an application that uses String method compareTo to compare two strings input by the user.
Output whether the first string is less than, equal to or greater than the second.
4. Write a program that displays a random lowercase letter using the Math.random() method.
5. Write a program that receives a character and displays its ASCII code (an integer between 1 and
127). Here is a sample run:
Enter a character: E <enter>
The ASCII code for character E is 69
We are also required to write a program that prompts the user to enter a password in which the password displays whether it is valid password or invalid password based on the password rule.
That’s all from me. Remain positive though it is impossible. Have a nice day ^_^
Nurazreen binti Mohd Nor (182433)
SSK3100 (Group 15)
SSK3100 (Group 15)
Next blog : kychoong.blogspot.com (Choong Kar Yee)