Count Number of characters in a Given String
SOURCE : ThirdLargest.javapublic class ThirdLargest { public static void main(String[] args) { int[] num = { 0, -87, 65, 87, 98, 76, 56 }; ThirdLargest tt = new ThirdLargest(); tt.max(num); } private void max(int[] num) { int maxone = 0; int maxtwo = 0; int maxthree = 0; try { for (int n : num) { if (maxone < n) { maxthree = maxtwo; maxtwo = maxone; maxone = n; } else if (maxtwo < n) { maxthree = maxtwo; maxtwo = n; } else if (maxthree < n) { maxthree = n; } } } catch (Exception e) { // TODO: handle exception } System.out.println("1st largest=:" + maxone); System.out.println("2nd largest=" + maxtwo); System.out.println("3rd largest=:" + maxthree); }}OUTPUT1st largest=:982nd largest=873rd largest=:76

0 comments :
Post a Comment