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
}
}
}
I do not use the AdGuard extension. I have uninstalled both the uBlock and Stylus extensions, as well as the Tampermonkey extension, since I began using AdGuard for Windows 7 months ago.
It does not use any extension APIs, it modifies traffic system wide using a local proxy. AdGuard performs all the functions of uBlock, as well as additional features such as HTTPS filtering, cosmetic (user scripts and user styles), as well as DNS. It works with any browser and application. I don't understand why you consider the desktop program to be useless...
Should Google be forced to stop promoting Chrome over other browsers?
Google pushes Chrome to anyone visiting its website using browsers other than Chrome.
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
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 } } }Link to comment
https://www.neowin.net/forum/topic/603102-java-converting-string-to-array/Share on other sites
13 answers to this question
Recommended Posts