Google an ASCII table and note that values from 48 to 122 represent characters i
ID: 3663017 • Letter: G
Question
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 Characterclass 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
Explanation / Answer
Please find below..
public class ASCIIGene {
int randNum;
public static void main(String[] args) {
int randNum = (int)((Math.random() * 75) + 48);
System.out.println("Random number is: "+randNum);
if(randNum>=48 && randNum<=57)
{
System.out.println("The ASCII Character for that is: "+(char)randNum);
System.out.println("This is a Number");
}
if(randNum>=58 && randNum<=64)
{
System.out.println("The ASCII Character for that is: "+(char)randNum);
System.out.println("This is a punctuation or a special character");
}
if(randNum>=65 && randNum<=90)
{
System.out.println("The ASCII Character for that is: "+(char)randNum);
System.out.println("This is a Upper Case letter");
}
if(randNum>=91 && randNum<=96)
{
System.out.println("The ASCII Character for that is: "+(char)randNum);
System.out.println("This is a punctuation or a special character");
}
if(randNum>=97 && randNum<=122)
{
System.out.println("The ASCII Character for that is: "+(char)randNum);
System.out.println("This is a Lower Case letter");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.