How do I use multidimensional arrays? [closed] - java

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
How would I use multidimensional arrays to store an x and y coordinate and the value that should be displayed at that coordinate. The swing tutorial really confused me and im not sure if you can read them the same way as a normal array. Here are my previous attempts:
private int[][][] idXY = new int[1000][1000][2];
int id;
public int[][] idPos(int x, int y){
return idXY[x][y][id];
}
public void setID(int x, int y, int ID){
idXY[x][y][ID] = {x}, {y}, {ID};
}
Im very sure that code doesn't make sence XD.
Thanks for your help,
AidoP

This is the syntax to store a value to a multidimensional array:
array[x][y] = value;
To access it:
array[x][y];
System.out.println(array[x][y]); // as an example

Related

Math calculations in java [closed]

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

Converting an array of ints to 1 int [closed]

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);

java array printing the repeated numbers , array in the array [closed]

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.

Regular expression to split geo-coordinates from a String [closed]

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));

How to check the positive and negative number's in a given arraylist in android or java? [closed]

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 set of int Arraylist for my application.For example
int[] array={10,8,-4,-6,5}
Here i want to check this array list.i am using this array for my bar graph chart.if all the value contains positive value,i want to show the graph in 0 to 100 % Y axis.if array contains negative value,i want to show the negative axis like -50 to 100 % depends upon the value.
How to do the logic for this problem.can anyone help me for my application?
boolean isNegative=false;
for(int i=0;i<array.length;i++)
{
if(array[i]<0)
{
isNegative=true;
break;
}
}
if(isNegative)
{
// code for displaying negative axis
}
else
{
//only display positive axis
}

Categories

Resources