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));
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
Is there an easy way(instead of hard coding) to display intermidiate calculation in java?
For example: x+y*3= 10+15*3=55
I have searching for an answer without success.
You could do something like this -
public static void main(String[] args) {
int x = 10;
int y = 15;
System.out.printf("x+y*3 = %d+%d*3 = %d", x, y, (x + (y * 3)));
}
Which outputs
x+y*3 = 10+15*3 = 55
here.
Try to learn parsing strings as shown here: http://www.javapractices.com/topic/TopicAction.do?Id=87
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
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);
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
I am looking for a regular expression to remove all #[x] present in a string
Where x can be any string.
For example #[title]
#\[[^\]]*\]?
As in:
String s = "asda #[asdagf] dsgfdg";
System.out.println(s.replaceAll("#\\[[^\\]]*\\]",""));
will print out:
asda dsgfdg
String original = "Hello #[world]!";
String replaced = original.replaceAll("#\\[.*?\\]", "");
// replaced = "Hello !"`enter code here`