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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


shawn mattison
need help with two dimensional array that takes input from user and bubble sorts and selections sorts
2 Answer(s)      2 years and 2 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.


Advertisement
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 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
Advertisements
php two dimensional array
php two dimensional array  php two dimensional array example
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
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. 
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 String dim2
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. ... in each of those arrays. To process a two-dimensional array, we use nested
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 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
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
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
 

 

 

DMCA.com