What I am trying to accomplish is: User inputs three arrays of strings for example
1, 11, 111; 2, 22, 222, 2222; 3, 33, 333, 3333, 33333
I need to get rid of the ,
's and put numbers into three arrays but it is storing weird results. Here's the code:
import java.util.Scanner;
public class signum {
static int[] eja = new int[10000];
static int[] tja = new int[10000];
static int[] kja = new int[10000];
private static String ej = null;
private static String tj = null;
private static String kj = null;
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Write a first array of integers");
ej = sc.nextLine();
ej = ej.replaceAll( "[^\\d]", " " );
System.out.println("Write a second array of integers");
tj = sc.nextLine();
tj = tj.replaceAll( "[^\\d]", "" );
System.out.println("Write the third array of integers");
kj = sc.nextLine();
kj = kj.replaceAll( "[^\\d]", " " );
for(int i = 0; i < ej.length(); i++) {
Character c = ej.charAt(i);
if(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' ||
c == '5' || c == '6' || c == '7' || c == '8' || c == '9') {
eja[i] = c;
System.out.println(eja[i]);
}
}
}
}
I know it still only tries to store the first array but the point is that if I try to store something like 1, 1, 1
it stored 49, 49, 49
.
Also i still have no idea how to make it store numbers that are > 9
, any ideas?
Thanks in advance! I am really out of ideas here..