need help with two dimensional array that takes input from user and bubble sorts and selections sorts

need help with two dimensional array that takes input from user and bubble sorts and selections sorts

I can get both of the sorts figured out but i cannot figure out how i can declare a two dimensional array without knowing how many elements are going to be in it. The number of elements will depend on how many words he/she types without using an array list.

View Answers

October 19, 2012 at 5:24 PM

Thank you. I am having problems with declaring the array. How do i do that without knowing how many elements are going to be input by the user?


October 19, 2012 at 12:32 PM

Here is a code that performs Bubble Sort using 2 d array.

public class BubbleSortWith2D {

  public static void main(String[] args) {
    int[][] a = {{3,24}, {4,56}, {1, 98}, {2,36}};

    bubbleSort(a);

    for(int i = 0;i<a.length;i++) {
      String s = "";
      for(int j=0;j<a[i].length;j++) s += a[i][j] + " ";
      System.out.println(s);
    }
  }

  public static void bubbleSort(int[][] array) {
    while(true) {
      boolean swapped = false;
      for(int i=0;i<array.length-1;i++) {
        if (array[i][0] > array[i+1][0]) {
          swapped = true;
          for(int j=0;j<array[i].length;j++) {
            int t = array[i][j];
            array[i][j] = array[i+1][j];
            array[i+1][j] = t;
          }
        }
      }
      if (!swapped) return;
    }
  }
}









Related Tutorials/Questions & Answers:
need help with two dimensional array that takes input from user and bubble sorts and selections sorts
need help with two dimensional array that takes input from user and bubble sorts and selections sorts  I can get both of the sorts figured out but i cannot figure out how i can declare a two dimensional array without knowing how
Need coding help - two dimensional matrix and it returns back a boolean.
Need coding help - two dimensional matrix and it returns back a boolean.  I need to write a code method that accepts a two dimensional integer arrays as the argument and returns true if the array or matrix is left or right
Advertisements
Need help in constructing bubble sort
Need help in constructing bubble sort  using a bubble sort, for each... by : (colon) sorted by the second dimension. I already got the two dimensional array figured out just couldnt dont know how to plug in the bubble sort
php two dimensional array
php two dimensional array  php two dimensional array example
two dimensional array
two dimensional array  how tow dimensional array works.How those loopes get incremented .and how every time the value of k changes
Two Dimensional array program
Two Dimensional array program  consider a two dimensional array... to elements of the array such that the last element become the first one and the first become the last.let the program output elements of the first array
Two- Dimensional Array - Java Beginners
Two- Dimensional Array  I am new in java programming. I am creating a two-dimensional array. This is my code ** class BinaryNumbers { public static void main(String[] args) { //create a two-dimensional array int ROWS = 21
Two Dimensional Array Program
Two Dimensional Array Program Using Nested for loop...; program . In this session we will teach how to use of a two dimensional array... are going to make two dimensional array having three row and three columns. 
how do i begin a two dimensional array?
how do i begin a two dimensional array?  I'm new to java programming and need to create a two dimensional array that enters exactly what is entered in the first dimension and then the first non-white space character of what
Two dimensional array in java
Two dimensional array in java. In this section you will learn about two-dimensional array in java with an example. As we know that array is a collection.... int arr[][]; Here arr is a two-dimensional array of type int. To create an array
Write a program that takes the marks of user as input
Write a program that takes the marks of user as input  Write a program that takes the marks of user as input. If marks are greater then 60 the program should display "Great, you have passed the course", else the program should
ModuleNotFoundError: No module named 'sorts-pr'
ModuleNotFoundError: No module named 'sorts-pr'  Hi, My Python... 'sorts-pr' How to remove the ModuleNotFoundError: No module named 'sorts-pr... to install padas library. You can install sorts-pr python with following
ModuleNotFoundError: No module named 'python-sorts'
ModuleNotFoundError: No module named 'python-sorts'  Hi, My Python... 'python-sorts' How to remove the ModuleNotFoundError: No module named 'python-sorts' error? Thanks   Hi, In your python
Two Dimensional Array Program
Two Dimensional Array Program    ... will learn how to display arrange form of two dimensional array program... a integer for array declaration Two dimensional array program. We are going
Managing Multiple User Input Data in an Array (or ArrayList)
Managing Multiple User Input Data in an Array (or ArrayList)  Hey... record alphabetically (2) If user chooses choice1, the input data is stored in an ARRAY (or ARRAYLIST) until the user chooses to stop inputting data. Kindly
error in taking input from user.
error in taking input from user.  //i m having problem inputting the array from user.my program is import java.io.*; class bubble { public static... java.util.*; class bubble { public static void main(String args[]) throws
Need help in constructing a 2 dimensionla array?
Need help in constructing a 2 dimensionla array?  Construct a 2 dimensional array that for each entry in the array, display the index of the first...[][]; for (int i=0; i   Here is an example of generating two-dimensional
Square Elements of Two Dimensional Array
the two dimensional array program and its square. This session provide you... Square Elements of Two Dimensional Array   ... array that contains integer type values. After this, we use two 'for' loop
XP Bowling Game User input help
XP Bowling Game User input help  I was asked to do the XP Bowling Example as an assignment. I have the programme passing all tests, but now I need to make the code accept input from a user and display the scores/frames
Two Dimensional Array Program Using Nested For Loop
Two Dimensional Array Program Using Nested For Loop ... dimensional array program. Firstly, we have to define class "TwoDimensional ". We are going to make a integer for array declaration Two dimensional array
reverse two dimensional arrays in java
reverse two dimensional arrays in java  reverse array elements in two dimensional array such that the last element becomes the first
Dividing Element of Two Dimensional Array
Dividing  Element of Two Dimensional Array...;ArrayDivideMatrix". Here you will learn how to use two matrix array for developing Java program.  The java two dimensional array program is operate the two
JavaScript Array from Input
JavaScript Array from Input   ... you easy to understand an example of  Array from Input. The example create a HTML Page JavaScript array from input include a text name 'name', a text field
A single dimensional array is called
A single dimensional array is called  What is a single dimensional array called?   A single dimensional array is called LIST
Array and input
to input one of the above numbers then i want to print the array without the number user input. how will i do tht...Array and input  if this is my array int briefcases
need help with program
need help with program  To write a program where we can take two integer array as input,Find the missing number from array"B" has all the numbers from array"A" except one,and find the fastest way in doing
one dimensional array program
one dimensional array program  Design and implement a java program that will read a file containing numbers and compute the following statistics...: - The first number in the input file will be the number of numbers in the file
two dimensional - Java Beginners
two dimensional  write a program to create a 3*3 array and print the sum of all the numbers stored in it.  Hi Friend, Try the following...; int sum=0; int[][] matrix; Scanner input = new
Need Help-How to store input parameter in DB through Java Bean - JSP-Servlet
Need Help-How to store input parameter in DB through Java Bean  Hello Sir, I have a simple Issue but It is not resolve by me i.e input parameter... open the table in Access. Its empty. Ms-Access have two fields- User, Password
Declare string array in Java (one and two dimensional)
Declare string array in Java (one and two dimensional... dimensional array and two dimensional as well. 1. String arr[] = new String...] + " "); } //declare and initialize two dimensional array
Two-dimensional arrays
; Two-dimensional arrays are defined as "an array of arrays"... of arrays of  ints". Such an array is said to be a two-dimensional array. ... A, and that there are 4 ints in each of those arrays. To process a two-dimensional array, we
Need help
Need help  Dear sir, I have a problem. How to write JSP coding, if a user select a value from drop down list for example department, the another drop.... This name list should get from the database. Please help me. By the way, I'm
one dimensional array using java
one dimensional array using java  design and implement a java program that will read a file containing numbers and compute the following statistics: the range(low,high) the average and the median
Need help - Java Beginners
, respectively. The program stores this matrix into a two dimensional m*n array...Need help   To Write a Java program that asks the users to enter a m... array as its argument, performs its transpose, and returns the transposed n * m
HELP WITH ARRAY
(" "); } } have the user input a number in the boxes.. if the number that the user input didn't match match with the number in the array boxes.. the output should be "Invalid Input" if it matches the number in the array boxes
Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which
Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which
Need help with this!
Need help with this!  Can anyone please help me... and then read back from the file if you want to delete or modify anything... to a file at all at this time. Any help would be greatly appreciated, thank you
Help With an Array
] < ) is wrong but I need help from this part on. I need that part corrected and add a portion that would ask the user to input a number, return...Help With an Array  // ******************** // Sales.java // // Reads
Need in desperate help in writing a console program
Need in desperate help in writing a console program  Write a console program that repeatedly prompts the user to enter data until they type done (any...: Bubble Sorted using a bubble sort, for each entry in the array, display
Need in desperate help in writing a console program
Need in desperate help in writing a console program  Write a console program that repeatedly prompts the user to enter data until they type done (any...: Bubble Sorted using a bubble sort, for each entry in the array, display
Need in desperate help in writing a console program
Need in desperate help in writing a console program  Write a console program that repeatedly prompts the user to enter data until they type done (any...: Bubble Sorted using a bubble sort, for each entry in the array, display
Need help with my project
Need help with my project  Uses a while loop to perform the following steps: -Prompt the user to input two integers: firstNum and secondNum where... prompt the user to input two integers and validate them. Then. we have
need help - Swing AWT
the letters and we the user may enter capital or small letters. then after extract each letter from this string and fill an array with 10 letter answers...need help  Create a program to correct and grade a set of multiple
escaping user input in php
escaping user input in php  Is it possible to escape the user input while submitting data into database in PHP
Java get User Input
Java get User Input       In this section, you will learn how to get the user input from... that will communicate with the user at the command line and returns the user input. We have
Netbeans Question need help desperately!!
a two-dimensional array to tally the actual combinations of rolls on 8 sided...Netbeans Question need help desperately!!   Ok here is my code- public class RollDie2 { public static void main(String[] args) { Random
Please help need quick!!! Thanks
Please help need quick!!! Thanks  hey i keep getting stupid compile... simulation program of sorts here is my code: RentforthBoatRace.java public...(){ Scanner input = new Scanner(System.in); double[] team = new double[10
Multi-dimensional arrays
that supports it, the element of the two-dimensional array x is denoted by x[i,j]. .... It does, however, supports an array of arrays. In Java, a two-dimensional array...; So far we have studied about the one-dimensional and two
Help With an Array
Help With an Array  So what Im trying to do is write an array... trying to do is almost combine the two to create a larger array declaration... not figure out how to finish the code. Please HELP! A) students? names

Ads