user2817797 user2817797 - 5 months ago 7x
Java Question

How do I convert a user-input integer into a char ASCII value in java?

I am trying to make a program where you can enter a credit card number and it will spit out the number back at you with a ASCII letter/symbol on the end using the remainder of the added digits divided by 26. I feel like my code is right although when I run the program, no symbol shows up. I do not get debug errors or anything, but my (char) symbol just doesn't show up. All it shows is the numbers. Can someone help me please?

Here is what I have so far:

import java.util.*;
import java.text.*;
import java.math.*;

public class Program{

public static void main (String []args){

Scanner keyboard = new Scanner(;

int CC, CC2, CC3, CC4;

System.out.println("Enter your credit card number 2 numbers at a time (XX XX XX XX)");

int CC6;

CC6= (CC+CC4+CC2+CC3)%26;

char CC7;

CC7 = (char)CC6;

System.out.println("The correct number and code is:" +CC+CC2+CC3+CC4+CC7);



Print them separately and you can see some weird symbol coming in the console.

System.out.println("The correct number and code is:" + CC + CC2 + CC3 + CC4);

The thing is, you'll get the CC7 in the range of 0-25 only since you're doing a mod 26 and this range contains ASCII codes of non-character keys.

Actual character(or for that case, special characters) start from ASCII code 33. Have a look at the ASCII table here.