i was watching a tutorial about bubblesort, and i followed all the instructions the difference is that the tutor is using System.out while im using JOPtionPane,
please help me thank you help me find my error and help me run it correctly!

public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		String ctr="";
		
		JOptionPane.showMessageDialog(null,"Enter any 10 numbers:");
		int[] points = new int[10];
	       
		 for (int i=1; i<=10+1;i++){
				
				points[i]=Integer.parseInt(JOptionPane.showInputDialog(null,"num["+i+"];"));
				
			
			ctr = ctr+points[i]+ " ";
			     
			 int[] sortedArray = bubbleSort(points);
		 }
	       
	       
		 
	      int sortedArray = 0;
			JOptionPane.showMessageDialog(null, "Numbers Entered: "+ctr+"Ascending:"+ sortedArray);
	        
	 	   
	}

	
	private static int[] bubbleSort(int[] points) {
				 		
	    int n=points.length;
		for(int pass=1; pass<=n;pass++){
		for(int current=0;current<n-pass;current++){
			if(points[current]>points[current+1]){
				int temp = points[current];
				points[current]=points[current+1];
				points[current+1]=temp;
			}
		}
			
		}
		return points;
		
		
	}

}

thanks so much!

i hope i can get my errors ryt away coz i have to pass it today! thank you!

At line 9;
An array has elements ranging from 0 up to size-1, you can't start at 1 there and end with 10+1

At line 9;
An array has elements ranging from 0 up to size-1, you can't start at 1 there and end with 10+1

what should i do?
should i delete that "+1"

whenever i run it something like this comes up:

Exception in thread "main" java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at finals.Gawa.main(Gawa.java:26)
and this:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at finals.Gawa.main(Gawa.java:26)

please help me thank you

yes remove it, start at 0 and make the condition less than 10

after that you need to change a few counters with your bubble sort to make it work

yes remove it, start at 0 and make the condition less than 10

after that you need to change a few counters with your bubble sort to make it work

yeah i still have an error on my bubblesort, and i dont know what it is, i know i followed the tutorial correctly but i cant seem to find my error on that part:!

int[] sortedArray = bubbleSort(points);

This function must be outside the for loop, that means you call the function only after you are done entering all the numbers.

EDIT : Post whatever errors/exceptions you are getting now

use

import javax.swing.*;

to use JOptionPane.

and change

for (int i=1; i<=10+1;i++)
{ 				
                   points[i]=Integer.parseInt(JOptionPane.showInputDialog(null,"num["+i+"];"));  			
                   ctr = ctr+points[i]+ " "; 			 
                   int[] sortedArray = bubbleSort(points);		 
}

to

for (int i=0; i<10;i++)
{		
		points[i]=Integer.parseInt(JOptionPane.showInputDialog(null,"num["+i+"];"));		
		ctr = ctr+points[i]+ " ";     
		int[] sortedArray = bubbleSort(points);
}
commented: you really should read previous posts once in a while -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.