- Joined
- Mar 3, 2005
- Location
- Jacksonville, FL
Hey guys I'm working on this project that's supposed to take integer input from the user and store it in array one integer at a time since the integer will be more then 20 digits. What I did is take users input as a String then used charAt to segment each character one by one.
The problem is when I stored it in array it gets stored as ASCII char code and I need it to be integer. Here is the code for my method:
So for example if I input 12345678, I get this:
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
Left side being string printed character at a time and right side I want it to be same as the left side but they need to be integers. If anyone knows how to deal with this is would be great help. I'm just not sure how to convert chartAt(index) to int and then stored it in my array.
Thanks again.
The problem is when I stored it in array it gets stored as ASCII char code and I need it to be integer. Here is the code for my method:
Code:
public void inputHugeIntegere()
{
int stringLength;
Scanner scan = new Scanner (System.in);
System.out.print("Please enter your huge integer: ");
input = scan.next();
stringLength = input.length();
stringLength--;
for (int index = 0; index <= stringLength; index++)
{
list[index] = input.charAt(index);
System.out.print(input.charAt(index) + "\t");
System.out.println(list[index]);
}
}
So for example if I input 12345678, I get this:
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
Left side being string printed character at a time and right side I want it to be same as the left side but they need to be integers. If anyone knows how to deal with this is would be great help. I'm just not sure how to convert chartAt(index) to int and then stored it in my array.
Thanks again.