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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started