import java.util.Scanner; class SecondLargest { public static void main(String[] args) { int secondlargest = Integer.MIN_VALUE; int largest = Integer.MIN_VALUE; Scanner input = new Scanner(System.in); System.out.println("Enter array values: "); int arr[] = new int[5]; for (int i = 0; i < arr.length; i++) { arr[i] = input.nextInt(); if (largest < arr[i]) { secondlargest = largest; largest = arr[i]; } if (secondlargest < arr[i] && largest != arr[i]) secondlargest = arr[i]; } System.out.println("Second Largest number is: " + secondlargest); } }
Search This Blog
Labels
- Apache Http Client (4)
- Array (3)
- Array List (12)
- Assertion (2)
- Calendar (20)
- Collection (7)
- Common Sol (14)
- Core Java (36)
- Date (4)
- Design Pattern (2)
- Display Tag (4)
- Eclipse (3)
- Enum (2)
- Exception Handling (5)
- How To (6)
- HttpURLConnection (2)
- ImageIO (2)
- Inner Class (1)
- Java Interview Q (1)
- Java IO (6)
- Java Mail (4)
- JDBC (1)
- JSON (5)
- JSP (2)
- JSTL (2)
- MYSQL (1)
- Platform Environment (3)
- Reg Ex (1)
- Serialization (1)
- Servers (3)
- Servlet JSP (3)
- Singleton Pattern (2)
- SQL (2)
- String Handling (11)
- Struts (5)
- Synchronization (5)
- Threads (6)
- Web Services (3)
0 comments:
Post a Comment