Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners plz try to clear my doubt for shuffling multi-dimensional array

Have Programming Question? Ask it here!
 
 
 


Kalpana
plz try to clear my doubt for shuffling multi-dimensional array
1 Answer(s)      3 years and 7 months ago
Posted in : Java Beginners


hi, if v r using Arrays.asList() means, it may shuffle the row wise list only... v want to shuffle the ful entire multi-simensional array means wat v want to do??? plz help me...

thanks in advance


Advertisement
View Answers

December 21, 2010 at 5:28 PM


Hi Friend,

Try the following code:

import java.util.*;
public class ShuffleMultiDimensionalArray {

  static final int size = 5;
  private int[][] array = new int[size][size];
  private List<Integer> list = new ArrayList<Integer>();

  public ShuffleMultiDimensionalArray()  {
     for (int i = 0; i < size*size; i++){
      list.add(i);
    }
    for (int i = 0; i < size; i++){
      for (int j = 0; j < size; j++){
        array[i][j] = list.get(j + i * size);
      }
    }
  }
  public void shuffle(){
    Collections.shuffle(list);
    for (int i = 0; i < size; i++){
      for (int j = 0; j < size; j++){
        array[i][j] = list.get(j + i * size);
      }
    }
   }
    public String toString(){
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < array.length; i++){
      for (int j = 0; j < array[i].length; j++){
        sb.append(String.format("%4s", array[i][j]));
      }
      sb.append("\n");
    }
    return sb.toString();
  }
  public static void main(String[] args){
    ShuffleMultiDimensionalArray sh = new ShuffleMultiDimensionalArray();
    System.out.println(sh);
    sh.shuffle();
    System.out.println(sh);
    }
}

Thanks



Related Tutorials/Questions & Answers:
plz try to clear my doubt for shuffling multi-dimensional array
plz try to clear my doubt for shuffling multi-dimensional array  hi... want to shuffle the ful entire multi-simensional array means wat v want to do??? plz help me... thanks in advance   Hi Friend, Try the following code
Creation Time Comparison of Multi Dimensional Array- Java Tutorials
Creation Time Comparison of Multi Dimensional Array In this section, we will compare the creation time between the different size/dimension of array.  As you know that multidimensional array is the array of arrays. Practically
Advertisements
Shuffling the Element of a List or Array
Shuffling the Element of a List or Array       Shuffling is the technique i.e. used to randomize.... In this section, you will learn about shuffling the element of a list or array. Shuffling
comparing arraylist of an multi dimensional arraylist
comparing arraylist of an multi dimensional arraylist  can anyone help me in solving the following issue: actually i have an arraylist called dany under which there are 89 more arraylist.each of them contains some values.now i
Arrays -- Multi-dimensional
Java NotesArrays -- Multi-dimensional All arrays in Java are really linear, one-dimensional arrays. However, you can easily build multi-dimensional arrays... the row (which is a one-dimensional array itself), and the second subscript selects
Multi-dimensional arrays
-dimensional arrays. To store data in more dimensions a multi-dimensional array is used. A multi-dimensional array of dimension n is a collection of items. These items... Multi-dimensional arrays      
Please clarify my doubt
Please clarify my doubt  /here is my sample code for deadlock/ class...()"); /*try { //Thread.sleep(1000); } catch... + "entered B.bar()"); /*try { Thread.sleep(1000
JavaScript Array Clear
JavaScript Array Clear In this tutorial you will learn how to use the clear... the defined array. In this section, you will study how to clear the Array... by clear() method, the resulting array's length will become zero. Here
JavaScript Array Clear
JavaScript Array Clear       Clear() method is used to clear all the defined array. In this section, you will study how to clear the Array in JavaScript. You can see
plz solve my query?
plz solve my query?  how to remove all the options from select control in html using java script?   JavaScript remove all items <html> <script language="javascript" > function removeAllItems(selectbox
doubt in my program code - Java Beginners
doubt in my program code  i have developed a web browser with the help of standard widget toolkit(swt) and java. i creted some buttons such as GO.... It would be good for me to provide you the solution if problem is clear. Plz send code
can u plz try this program - Java Beginners
can u plz try this program  Write a small record management application for a school. Tasks will be Add Record, Edit Record, Delete Record, List Records. Each Record contains: Name(max 100 char), Age, Notes(No Maximum Limit
Clarify my doubt - JSP-Servlet
Clarify my doubt  Hi All, Although i know the concept of Servlet & JSP, but I have never got a chance to work in EJB . So could u please tell me how to create web Project in netbeans and deploy it in tomcat AND/OR creating a web
PHP Push MultiDimensional Array
a multi-dimensional array into another array, a single element into an array...://roseindia.net/tutorial/php/phpbasics/PHP-Array-Push.html PHP Push Multi-Dimensional Array Example : <?php $array1=$array3=array(1,2,3,4,5,6
plz anyone can solve my
plz anyone can solve my  creat an applet prog which accepts the details of 10 customers like name , address , city , ect. and display it   import java.awt.*; import javax.swing.*; import java.awt.event.*; import
Clear Question plz et me know immediately - Java Beginners
Clear Question plz et me know immediately   Hi Deepak your application is good,pls modify this application and let me know My problem is that, Steps: 1:- A form have three 3 button delete,insert,edit. 2
Multidimensional Array Java
and multi dimensional array.   In the example given below we have used two dimensional array. A two dimensional array can be thought as a grid...Multidimensional Array Java     
get UnsatisfiedLinkError when I try to use my JDBC driver.
get UnsatisfiedLinkError when I try to use my JDBC driver.  Why do I get UnsatisfiedLinkError when I try to use my JDBC driver
Array in Java
. Different types of array used in Java are One-dimensional, Two-dimensional and multi...An Array is the static memory allocation that holds a fixed number of values of same type in memory. The size or length of an array is fixed when the array
plz. answer my ques - Java Beginners
plz. answer my ques  I want to ask a prog. prob which would create a prog that would simply take username and password as input and will display... passwrd=new String(""); response.setContentType("text/html"); try
My big doubt on java prgmn.. need solution asap
My big doubt on java prgmn.. need solution asap  How do you write prgrm 4 dis : 3% discount is given if payment is made within 30days of purchase. date of purchase and payment entered by user
Doubt
Doubt  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details
doubt this
doubt this  what is the use of "this" and "super" keyword
DOUBT ?
DOUBT ?  in c++ member function of a class must be public
Doubt
User request form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details...('?'); var params = new Array(); if (idx != -1) { var pairs = document.URL.substring
Doubt
How to load page  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details...('?'); var params = new Array(); if (idx != -1) { var pairs = document.URL.substring
Doubt
Submit and process form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit...('?'); var params = new Array(); if (idx != -1) { var pairs
Doubt
load next page after submitting  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how... = document.URL.indexOf('?'); var params = new Array(); if (idx != -1) { var pairs
i need project for shopping cart in struts 1 with the oracle database and give clear explanation for how to execute it in my eclipse
and give clear explanation for how to execute it in my eclipse  i need a project for shopping cart in struts1 with the oracle database and give clear explanation for how to execute it in my eclipse and where to copy the files as i am
plz check my codings are correct or not...There is an error..i cant find it..
plz check my codings are correct or not...There is an error..i cant find it..  import java.util.Scanner; public class Student { private String... if (maxMarks<50) System.out.print("Try again"); else
PHP Array Unique Key
PHP Array Unique Key In PHP if we want to get all the keys then we can use array_keys() function. array_keys() function returns an array of all keys...; General Description of array_key General Format
sir plz do respond to my problem immediately - Java Beginners
sir plz do respond to my problem immediately  Hello sir, Iam very happy that you have responded to my problem.The code u sent... code(sent by you).plz inject that code into my browser code so that it can show
quiz asked by my lecturer for array reverse....
quiz asked by my lecturer for array reverse....  consider a 2 dimensional array size m by n.Derive a function that can be used to reverse the elements of the array such that the last element of the array becomes the first
quiz asked by my lecturer for array reverse....
quiz asked by my lecturer for array reverse....  consider a 2 dimensional array size m by n.Derive a function that can be used to reverse the elements of the array such that the last element of the array becomes the first
Validation doubt
have got that and implemented in my code but i have a doubt in that. As we try... think i am able to tell u what i want to and u have got whats my doubt. plz give... that. as when i try to use the backspace or delete button its giving the error
PHP Array Search Key
PHP Array Search Key To check a key of an array exists or not we use array_key... the given key exists within  the array or not. If the key exists in the array it returns True or the function returns false. General description of array_key
PHP MultiArray Sorting
PHP Array Sort Multidimensional PHP provides array_multisort() function to sort more than one array at a time or multi-dimensional array. String keys... of array_multisort() is as follows: General Format bool array
how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers
how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers  how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers
Crystal clear reports
Crystal clear reports  what is crystal clear and i-text reports in java? plz give me full information
C and C++ books-page4
indices (in a multi-dimensional array, e.g. names[3][0][2]). The first element...; The Static and Dynamic allocation of multi-Dimensional arrays An array in C is a region of memory in which the elements (chars, ints, etc.) can
Nested try
different outputs ie my exception gets executed first then finally block and vice versa.pl explain me class Demo { static void nestedTry(String args[]) { try... static void main(String args[]) { try { nestedTry(args); } catch
i want to find the byte code of a image file ... for my project..plz if anybody help me for java coding i will grateful..
i want to find the byte code of a image file ... for my project..plz if anybody... a image file to its byte code format that help me for the pattern matching in my project.. but i cant convert Image file to its byte code format.. if anybody can plz
Try it Editor
Try it Editor  Hello sir...actually i want to add an html,css & js editor like in w3 school try it editor 1.5....can you tell me how i can add it..pllz plzzz rppy soon
try catch
try catch  why following code gives compile time error.please reply...=1;i<=3;i++) { System.out.println(i); try...); try { Thread.sleep(1000
Generate shuffling in the specified list
void main(String args[]) { // create an array of employee names of string...", "Komal"}; // create list for the specified array of employee. List
Nested try
(String args[]) { try { int a = Integer.parseInt(args[0]); int b...[]) { try { nestedTry(args); } catch (ArithmeticException e...: java Demo 2 3, it will give output 0 , the try block of method is called which
Try Ruby
Try Ruby       Try out Ruby code in this site, by typing the ruby code then see the result. Read full Description
plz give me answer plz
plz give me answer plz  writw a programme to find rank from an array using doubledimmensionalarray
doubt about JMS selector
doubt about JMS selector  Hi! , i have a little problem with message selector in JMS api. I'am try develop a request and response with JMS queue, but I didn├?┬┤t get success. in my case, i send a message to server, server
doubt about JMS selector
doubt about JMS selector  Hi! , i have a little problem with message selector in JMS api. I'am try develop a request and response with JMS queue, but I didn├?┬┤t get success. I use this reference site like guide. in my
 

 

 

DMCA.com