Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Number.java Program asks the user to input a number between 0-25. •Put in code t

ID: 3589111 • Letter: N

Question

Number.java

Program asks the user to input a number between 0-25.

•Put in code to check if the input number is within the valid range and print “* character of the alphabet is *”

•It will basically print alphabets from A to Z

•If the number is 0 then the output is “0 character of the alphabet is A”

•... so on ...

•If the number is 25 then the output is “25 character of the alphabet is Z”

•If the number is invalid then it should say “Outside of acceptable range”

Assessment

Enter the following values by running Number.java after your modification and explain the behavior.

1

20

1000

500000000000

-500000000000

12,345

789.543

-0

Explanation / Answer

import java.util.Scanner;

public class Number {

/**

* @param args

*/

public static void main(String[] args) {

Scanner scanner = null;

try {

// declaration

scanner = new Scanner(System.in);

int n;

// prompt to enter the number

System.out.print("Enter the number between 0-25: ");

n = scanner.nextInt();

// check the number is in the range

if (n >= 0 && n <= 25) {

System.out.printf("%d character of the alphabet is %c ", n,

(65 + n));

} else

System.out.println("Invalid Number!");

} catch (Exception e) {

// TODO: handle exception

System.out.println("Invalid Number!");

}

}

}

OUTPUT:

Test 1:
Enter the number between 0-25: 1
1 character of the alphabet is B

Test 2:
Enter the number between 0-25: 20
20 character of the alphabet is U

Test 3:
Enter the number between 0-25: 10000
Invalid Number!

Test 4:
Enter the number between 0-25: 789.543
Invalid Number!