68 719
Assignments Done
Successfully Done
In January 2019

Answer to Question #57917 in Java | JSP | JSF for kenya

Question #57917
2. Google an ASCII table and note that values from 48 to 122 represent characters in three categories; digits, special characters, or letters of the alphabet. Write a Java program that generates a random integer from 48 to 122, inclusive. Then use methods of the Character class in selections to detect and report the ASCII category of the character for that integer. Include case if the character is a letter. See example outputs below.
Example Outputs

The integer is 71
The ASCII character for that is G
That is an upper case letter

The integer is 61
The ASCII character for that is =
That is punctuation or a special character

The integer is 102
The ASCII character for that is f
That is a lower case letter
Expert's answer
import java.util.Random;

public class CharGenerate {
public static void main(String[] args) {
Random random = new Random();
int c;
for(int i = 0; i < 5; i++) {
c = random.nextInt(75) + 48;

public static void showCharInfo(int c) {
char ch = (char) c;
System.out.println("The integer is " + c);
System.out.println("The ASCII character for that is " + (char)c);
System.out.println("That is digits");
else if(Character.isUpperCase(c))
System.out.println("That is an upper case letter");
else if(Character.isLowerCase(c))
System.out.println("That is a lower case letter");
else System.out.println("This is punctuation or a special character");

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions