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



Home Answers Viewqa Java-Beginners Help With My Java Project?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


philippines
Help With My Java Project?
0 Answer(s)      2 years and 4 months ago
Posted in : Java Beginners


Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two-dimension array where the first dimension contains exactly what they type and the second dimension contains the first non-whitespace character of what they type, in lowercase. If they enter a blank line, it is acceptable to skip that line. When they type done, do these steps: display: As Entered for each entry in the array, display the index of the first dimension, the second dimension's value, and the first dimension's value on a single line separated by : (colon). display: Bubble Sorted using a bubble sort, for each entry in the array, display the original index of the first dimension, the second dimension's value, and the first dimension's value on a single line separated by : (colon) sorted by the second dimension. display: Selection Sorted using a selection sort, for each entry in the array, display the original index of the first dimension, the second dimension's value, and the first dimension's value on a single line separated by : (colon) sorted by the first dimension. Grading Notes:

Example:

User types: apple Apple Zone apple done

You display: As entered 0:a:apple 1:a:Apple 2:z:Zone 3:a:apple Bubble Sorted 0:a:apple 1:a:Apple 3:a:apple 2:z:Zone Selection Sorted 1:a:Apple 0:a:apple 3:a:apple 2:z:Zone

Here is what i got and i cant seem to put it all together to make it work. please help

import java.util.Scanner;
import java.util.*;
public class A4A
{
    public static void main(String[] args) { 
        Scanner input=new Scanner(System.in);
        System.out.print("Enter value of i: ");
        int a=input.nextInt();

System.out.print("Enter value of j: "); int b=input.nextInt(); int[][] a2 = new int[a][b]; System.out.println("Enter elements of your choice: "); for(int i=0 ; i < a2.length ; i++){ for(int j=0 ; j < a2[i].length ; j++){ a2[i][j] = input.nextInt(); } } for(int i=0 ; i < a2.length ; i++){ System.out.println(); for(int j=0 ; j < a2[i].length ; j++){ System.out.print(a2[i][j]+" "); } } } } static class bubbleSort{ { int i; int array[] = {12,9,4,99,120,1,3,10}; System.out.println("Values Before the sort:\n"); for(i = 0; i < array.length; i++) System.out.print( array[i]+" "); System.out.println(); bubble_srt(array, array.length); System.out.print("Values after the sort:\n"); for(i = 0; i public static void bubble_srt( int a[], int n ){ int i, j,t=0; for(i = 0; i < n; i++){ for(j = 1; j < (n-i); j++){ if(a[j-1] > a[j]){ t = a[j-1]; a[j-1]=a[j]; a[j]=t; } } } } } public static void selection_srt(int array[], int n){ for(int x=0; xofmin = x; for(int y=x; yofmin]ofmin = y; } } int temp = array[x]; array[x] = array[indexofmin]; array[indexofmin] = temp; } } }

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com