Home Answers Viewqa Java-Beginners need help with two dimensional array that takes input from user and bubble sorts and selections sorts

 
 


shawn mattison
need help with two dimensional array that takes input from user and bubble sorts and selections sorts
2 Answer(s)      7 months ago
Posted in : Java Beginners

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 Pages:
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
Bubble Sorts
Java NotesBubble Sorts People like bubble sorts -- could it be the name? One nice aspect of bubble sorts is that they can quit early if the elements... no exchanges, shorter range each time This version of bubble sort combines ideas from
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
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
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
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
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
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. 
php two dimensional array
php two dimensional array  php two dimensional array example
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
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
Bubble Sorting in Java
algorithm. In bubble sort algorithm array is traversed from 0 to the length-1..., bubble sorting algorithm compare two values and put the largest value... the values of array is sorted. In worst-case the complexity of bubble sort
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
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
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
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
input output
data types from the input stream in a machine format.... FileInputStream It contains the input byte from a file.... StreamTokenizer It takes an input stream and parse
Help With an Array
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 the "salesperson" id tag's...Help With an Array  // ******************** // Sales.java // // Reads
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
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
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
Square Elements of Two Dimensional Array
the two dimensional array program and its square. This session provide you... Square Elements of Two Dimensional Array   ...: We are going to display the square of two matrix. Firstly, we have to define
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
Arrays -- Multi-dimensional
the element in that row/array. Visualizing two-dimensional arrays Assume we...] | | | +-----+-----+-----+-----+ +-----+ In Java two-dimensional arrays are implemented is a one-dimensional array... from these, and Java has features in the language to help you do
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
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
Bidirectional Bubble Sort in Java
-directional bubble sort algorithm to sort the values of an array.  ... Bidirectional Bubble Sort in Java       Introduction : Bidirectional Bubble Sort
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
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
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
button to accept user input
the radiobutton and spinner.The user input does not show on my Studentinfo.mdb... that accepts firstname, lastname and gender from user and insert to database...button to accept user input  private void jButton1ActionPerformed
Input And Output
This class reads the primitive data types from the input stream... byte from a file and implements an input stream... standard input to read the user input.. In this section, you will see how
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
Android Application Development is a Wide Open Process
of different types of Android phones that are available from all sorts... be found in many forms. A major reason as to why this is so comes from how... operating systems. It is used to help with getting all of the coding
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
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...-dimensional array; the expression x[i][j] is ued to select the element from that array
Keyboard Input
Java NotesKeyboard Input There are two approaches to getting keyboard input from the user. GUI (Graphical User Interface). Displaying a graphical text... for reading from text files. Graphical User Interface This is how
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
i need a help in this please
i need a help in this please  The factorial of a nonnegative integer... that reads a nonegative integer from the user and computes and print its factorial. b... Factorial{ public static void main(String[] args) { Scanner input
Sorting the array
: one for integer votes to be input by the user and one for the names which you should initialise in the program ? you will need to modify the input method from... to modify the sort method from the lectures so that it sorts into descending order
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
need help...................please
need help...................please  I have a problem in my JSP Coding. How to retrive value from database in to text field when user select one value from dropdown list. For example, if user select on of name in dropdown 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
Logic and desgin HELP just need to get started on this.
Logic and desgin HELP just need to get started on this.   Write a program that accepts five homework scores as input values and stores them.... Accept the dollar value of each item purchased from the user until the user
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
input
input  a java program that will exchange the last names of two students that were input by a user
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
need help pleaseee....i weak in java
need help pleaseee....i weak in java  QUESTION 1 You are required... users and calculate the charges based on data entered by the user. Data needed... must be able to hold information for up to 5 customers. Use an array

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.