We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.util.*;classSolution{publicstaticvoidmain(String[]args){//InputScannersc=newScanner(System.in);intn=sc.nextInt();String[]s=newString[n+2];for(inti=0;i<n;i++){s[i]=sc.next();}sc.close();//Write your code herefor(inti=0;i<n;i++){//inserting string values to bigdecimalBigDecimalFirst=newBigDecimal(s[i]);intindex=i;for(intj=i+1;j<n;j++){//second BigDecimal to compare the first BigdecimalBigDecimalSecond=newBigDecimal(s[j]);//comparing if First element is greater that second element//if the First element is greater than Second element than compareTo() returns 1if(Second.compareTo(First)==1){First=Second;index=j;}}//temporary variable to store s[i] valueStringtemp=s[i];s[i]=s[index];s[index]=temp;}//Outputfor(inti=0;i<n;i++){System.out.println(s[i]);}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java BigDecimal
You are viewing a single comment's thread. Return to all comments →