Question: Java assist. I have the following code I need to determine the issues and fix it. I have fixed a couple, you can see that

Java assist.

I have the following code I need to determine the issues and fix it. I have fixed a couple, you can see that below, but I am stuck on the next issues. Can you please help?

////Original.java////

import java.util.Scanner; class BubbleSort { public static main(String []args) { int n, c, swap; Scanner in = new Scanner(System); System.out.println("Input number of integers to sort"); n = nextInt(); int array = new int[n]; System.out.println("Enter " + n + " integers"); for (c = 0; c < n; c++) array = in.nextInt(); for (c = 0; c < ( n - 1 ); c++) { for (d = 0; d < n - c - 1; d++) { if (array[d] > array[d+1]) /* For descending order use < */ { swap = array[d]; array[d] = array[d+1]; array[d+1] = swap; } } } System.out.println("Sorted list of numbers"); for (c = 0; c = n; c++) System.out.println(array[c]); } }

////Fixed so far/////

//Changed this from java.util.scanner because I wanted a larger range declared import java.util.*; //Issue 1: class needs to be changed to Public Class public class BubbleSort {

//Issue 2: Needs to be public static void main public static void main(String[]args) { int n, c, swap;

//Issue 3: Changed from "Scanner in = new Scanner(System);"" Scanner sc = new Scanner(System.in); System.out.println("Input number of integers to sort");

n = nextInt(); int array = new int[n]; System.out.println("Enter " + n + " integers"); for (c = 0; c < n; c++) array = in.nextInt(); for (c = 0; c < ( n - 1 ); c++) { for (d = 0; d < n - c - 1; d++) { if (array[d] > array[d+1]) /* For descending order use < */ { swap = array[d]; array[d] = array[d+1]; array[d+1] = swap; } } } System.out.println("Sorted list of numbers"); for (c = 0; c = n; c++) System.out.println(array[c]); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!