I am in the process of writing simple a java program where I have to add arrays. This is what I am tying to do:
>Have my users input numbers ex: 12345
>put that input into an array with the data looking like: arr1[] = [1,2,3,4,5)
>
This is what I have. I am having the problem converting the string into an int array
import java.util.ArrayList;
import java.util.*;
public class Adding
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String s = in.next();
System.out.println(s);
int [] n1 = new int [s.length()];
for(int i = s.length() - 1; i >= 0; i++)
{
char c = s.charAt(i);
int d = (int) c - (int) '0';
//this is where I am stuck - adding the data into the array
}
}
}
Question
dykemike
I am in the process of writing simple a java program where I have to add arrays. This is what I am tying to do:
>Have my users input numbers ex: 12345
>put that input into an array with the data looking like: arr1[] = [1,2,3,4,5)
>
This is what I have. I am having the problem converting the string into an int array
Link to comment
Share on other sites
13 answers to this question
Recommended Posts