+ 3
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("enter the length of Arrays ");
int n;
n=in.nextInt();
int arr[]= new int[n];
System.out.println("enter"+n+"no of integers");
for (int i=0;i<n;i++)
arr[i]=in.nextInt();
boolean swapped = true;
for(int i=0; i<n-1; i++) {
swapped = false;
for(int j=0; j<n-i-1; j++) {
if(arr[j] > arr[j+1]) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
swapped = true;
}
}
if(swapped == false)
break;
}
for(int i=0; i<n; i++) {
System.out.print(arr[i] + " ");
}
}
}
#this will work
+ 3
Check lines 8 and 12 of your code. Replace with these, respectively:
n = in.nextInt(); // line 8
arr[i] = in.nextInt(); // line 12
Keep in mind, it should be "in.nextInt()", not "int.nextInt()" or "in.nextInt" ^^
+ 2
Ganesh Reddy this should work.
https://code.sololearn.com/cxyNRWQQaCbS/?ref=app



