• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

  • Home
  • Interview Questions
  • Java
  • Java Programs
  • Selenium
  • Selenium Programs
  • Manual Testing
  • Test Cases
  • Difference
  • Tools
  • SQL
  • Contact Us
  • Search
SoftwareTestingo » Java » Java Programs » How to Find Second Highest Number In An Array Example Program?

How to Find Second Highest Number In An Array Example Program?

Last Updated on: January 15, 2019 By Softwaretestingo Editorial Board

What We Are Learn On This Post

  • How to Find Second Highest Number In An Array Example Program?

How to Find Second Highest Number In An Array Example Program?

package com.softwaretestingblog.programs;
public class SecondHighestNumber {
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      int numbers[] = {6,3,37,12,46,5,64,21};
      int highest = 0;
      int second_highest = 0;
      for(int n:numbers){
         if(highest < n){
            second_highest = highest;
            highest =n;
         } 
         else if(second_highest < n){

            second_highest = n;
         }
      }
      System.out.println("Second Highest Number: "+second_highest);
   }
}

Output:

Second Max Number: 46

    Filed Under: Java Programs

    Reader Interactions

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Primary Sidebar

    Join SoftwareTestingo Telegram Group

    Categories

    Copyright © 2022 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy ~ Testing Careers