User determined array dimensions [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to write a program Minesweeper.java that takes 3 command-line arguments M, N, and p and produces an M-by-N boolean array where each entry is occupied with probability p. Where I'm stuck is how to create a two dimensional array where the user inputs what the dimensions are. Any help with that part would be great, thanks :)

Here you go the main method:
public static void main(String args[]) {
int a = Integer.valueOf(args[0]);
int b = Integer.valueOf(args[1]);
int myArray[][] = new int[a][b];
//your code
}
It's java. Chapter 0

Related

I don't know why my code is working without using arraylist in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
This code is working correctly but i havn't used arraylist but it is working properly. Can anyone answer it?
import java.util.Arrays;
import java.util.Collections;
class findMinMax{
public static void main(String[] args){
Integer[] arr2 = {2,1,35,-6,-2,6,9};
int mymin = Collections.min(Arrays.asList(arr2));
int mymax = Collections.max(Arrays.asList(arr2));
System.out.println(mymin);
System.out.println(mymax);
}
}
Arrays.asList takes Array as input and returns a new ArrayList with elements of array as its element and returned ArrayList is not resizable

how to create loops in which create a star pyramid based on user input [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
(java) Write an application that will ask the user to enter a positive integer. Based on the user input, your program must use a loop(s) to create a pattern of stars, each subsequent row must have one less star.
input:
5
output
*****
****
***
**
*
void printStars(int num){
for(int i=num;i>0;--i){
for(int j=0;j<i;++j){
System.out.println("*");
}
System.out.println("");
}
}
The above code should help.

Why Does code.runnable.com Allow Me to Change a Variable's Value in Java? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I heard that Java integers are pass by value, so why does the following code work in code.runnable.com?
public class HelloWorld {
public static void main(String[] args) {
int number = 0;
number = 2;
System.out.println(number);
}
}
The code will print out 2.
This code snippet doesn't pass number anywhere. You're declaring a local variable and then overriding its initial value. This is perfectly legal in Java, and has nothing to do with passing by reference or by value.

c strange use of srand and rand c [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Can you help me to understand what is the meaning of these randomization?
I have found it in a c code that I have to translate, it return always 41:
int main(){
srand(1);
printf("\n%d",rand());
}
How I can emulate the srand(1) and rand() in Java?
My answer assumes that you just want to emulate the behavior of srand() and rand(), but do not care about the '41' you say that you always get.
This is basically just the idea of pseudo-random number generation. If you set the seed to a constant value (1 in this case), then call the random() function, it will always return the same value. This is because it is basically saying "set the index to 1 in the big list of 'random' numbers" so that the next time I call random it returns the n-th value in that 'list'. In reality, it is a bit more complex, but that's how I like to think about it sometimes. To emulate the behavior of your code in Java, you can try the following:
public static void main(String[] args) {
Random rand = new Random(1);
System.out.println(String.valueOf(rand.nextInt()));
}

Writing a method using getArray() in Java that returns an array of integers [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am in a a JAVA programming class online and I need some help with making an array. I have asked some fellow class mates to no avail. I need to make write a method using the getArray() method that will return an array of integers with the capacity of 500.
I do know how to write a JAVA statement that initializes an array of integers with a capacity of 500. However, it nots helping me much. (i named the array "values")
int [] values = new int [500];
Please be timely if you answer this. I need to know how to do this before Wednesday 2/5/14 Thank You
public int[] getArray(){
return new int[500];
}

Categories

Resources