Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to convert an array of ints to 1 int.
e.g. I have an array of ints {1,2,3,4,5} and want to convert it to the int 12345
How do I do this?
Iterate through the array, and concatenate the values to String and convert that String to int
String valueSt = "";
for(int val : array) {
valueSt += val;
}
int finalValue = Integer.valueOf(valueSt);
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to use setText(..) and sending a double value to it but it says
setText(java.lang.String) in javax.swing.text.JTextComponent cannot be applied to (double)
You need to convert your double to a String and then pass that String as an argument to the setText(String) method. This is how you convert a double to a String:
double d = 3.14;
String s = String.valueOf(d);
// s is now "3.14"
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Please could you tell me how its work in section (g[ss[i]]++;) and tell me the sequence of output in java
class A{
public static void main(String []a){
int []ss={1,2,3,4,2,3,3,1,1,1,5,6,4,5,4};
int []g=new int[15];
for(int i=0;i<15;i++){
g[ss[i]]++;
}
for(int i=1;i<15;i++){
System.out.println(ss[i-1]+"=="+g[i]);
}
}
}
Can't you run it?
g[ss[i]]++; can be rewritten as
int index = ss[i];
g[index] = g[index] + 1;
So it's counted number of each number in ss.
It's very error prone, and you should never do something like that.
Just run it?
1==4
2==2
3==3
4==3
2==2
3==1
3==0
1==0
1==0
1==0
5==0
6==0
4==0
5==0
This should be your output.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
So I'm trying to learn algorithm efficiency. I know how to remove one element from the array, but not sure how to remove between two indices. Lets pretend that the
list = {1,2,3,4,5,6,7,8,9,10}, and we call the removeBetween method with arguments:
removeBetween(2, 6);
public void removeBetween(int FirstIndex, int LastIndex)
{
}
A general algorithmic direction you can follow :
To remove all numbers between 2 given indices, say (FirstIndex, LastIndex):
Copy all elements from index 0 to FirstIndex to a result array.
Next copy all elements from LastIndex to Array.lenght()-1 indices to the same result array above.
Return result.
so if you have your items in an array list you can do something like:
ArrayList<Whatever object is> newElements = yourlist.sublist( 0, firstIndex );
newElements.addAll( yourlist.subList( LastIndex + 1, yourlist.size() ) ;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have geo-coordinates in a String like the one given below.
[79.9016492,6.8632761]
I need to get the two numbers separated as double values. Can someone please help me with writing a regular expression?
For [79.9016492,6.8632761] string, it is
String[] oxoy = "[79.9016492,6.8632761]".split("[\\[\\],]");
String x = oxoy[1]; // 79.9016492
String y = oxoy[2]; // 6.8632761
Ideone DEMO
Convert to double
Double x1 = Double.valueOf(x);
Double y1 = Double.valueOf(y);
Not exactly regex, but you can get it very easily as follows:
String[] a = "[79.9016492,6.8632761]".split(",");
double x = Double.valueOf(a[0].substring(1));
double y = Double.valueOf(a[1].substring(0,a[1].length()-1));
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am reading an array of bytes from a page as a String. Example: "80 75 7 8 0 0".
I would like to convert this String into a byte array in Java. Can anyone help me/tell me what method I can possibly use?
Thank you.
Try:
String[] bytesString = originalString.split(" ");
byte[] bytes = new byte[bytesString.length];
for(int i = 0 ; i < bytes.length ; ++i) {
bytes[i] = Byte.parseByte(bytesString[i]);
}