Definition of an array
- int[] arr = new INT[5];
- int[] arr = new int[]{1,2,3,4}
- Int[] arr = {1,2,3,4}
Take the maximum value in the array
Public Static void Main (string[] args) { int[] va = {45,7,67,87,98,0,45,78,100}; int tmp = va[0]; for (int i=1;i<va.length;i++) { if(tmp<va[i]) { = va[ I]; I+ +; } }
SYSTEM.OUT.PRINTLN (TMP); Maximum Value }
Select sort
Public Static voidMain (string[] args) {int[] va = {45,7,67,87,98,0,45,78,100}; intTmp=va[0]; for(inti=0;i<va.length-1;i++){ for(inty=i+1;y<va.length;y++){ if(va[i]>Va[y]) {tmp=Va[i]; Va[i]=Va[y]; Va[y]=tmp; } } } for(intI:va) {System.out.print (i); System.out.print (" "); } }
Bubble sort
Public Static voidMain (string[] args) {int[] va = {45,7,67,87,98,0,45,78,100}; intTmp=va[0]; for(inti=0;i<va.length-1;i++){ for(inty=0;y<va.length-1-i;y++){ if(Va[y] > va[y+1]) {tmp=Va[y]; Va[y]= Va[y+1]; Va[y+1] =tmp; } } } for(intI:va) {System.out.print (i); System.out.print (" "); } }
Array Common operations