Solution.java:7: error: '{' expected public class bubbleSort(int[] a) { ^ Solution.java:7: error: ';' expected public class bubbleSort(int[] a) { ^ Solution.java:9: error: illegal start of expression public bubbleSort(int[] a){ ^ Solution.java:9: error: '.class' expected public bubbleSort(int[] a){ ^ Solution.java:9: error: ';' expected public bubbleSort(int[] a){ ^ Solution.java:56: error: reached end of file while parsing } ^ 6 errors
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class bubbleSort(int[] a) { public bubbleSort(int[] a){ int endPosition = a.length - 1; int swapPosition; while( endPosition > 0 ) { swapPosition = 0; swapNum =0; for(int i = 0; i < endPosition; i++) { if( a[i] > a[i + 1] ){ // Swap elements 'i' and 'i + 1': int tmp = a[i]; a[i] = a[i + 1]; a[i + 1] = tmp; swapPosition = i; swapNum++; } } } firstElement = a[0]; lastElement = a[a.length -1]; System.out.println("Array is sorted in "+ swapNum + " swaps."); System.out.println("First Element: "+ firstElement); System.out.println("Last Element: "+ lastElement); } } // end bubbleSort public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] a = new int[n]; for(int a_i=0; a_i < n; a_i++){ a[a_i] = in.nextInt(); } bubbleSort instance = new bubbleSort(a); instance(a); } }
public class bubbleSort(int[] a) {
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)