Given an array of integers, write a method, findSecondHighestNumber, that returns the second highest number in the array. For example, when the code below is run, we expect to see the answer: 2 public static void main ( String [] args) { int [] numbers = new int []{ 1 , 2 , 3 }; int number = findSecondHighestNumber ( numbers ); System . out .println( number ); } We expect a solution that can handle any length of array from 0 to 100 numbers. Answer : package com.gsr; public class FindSecondHighestNumber { public static void main(String[] args ) { int [] numbers = new int []{1,2,3,-4,5,12, 35, 34, 10, 34, 1}; int number = findSecondHighestNumber ( numbers ); System. out .println( number ); } private static int findSecondHighestNumber( int [] numbers...
Posts
Rest API Versioning
- Get link
- X
- Other Apps
Q How many ways to recommended to use common REST API versioning strategies : Ans : Versioning is a crucial part of API design. It gives developers the ability to improve their API without breaking the client’s applications when new updates are rolled out. Four ways : 1 Versioning through URI Path http://www.example.com/api/ 1 /products 2. Versioning through query parameters http://www.example.com/api/products?version=1 3. Versioning through custom headers curl -H “Accepts-version: 1.0” http://www.example.com/api/products 4 Versioning through content negotiation curl -H "Accept: application/vnd.xm.device+json; version=1 ” http://www.example.com/api/products
How many ways to iterate in HashMap ?
- Get link
- X
- Other Apps
Q How many ways to iterate in HashMap ? Ans : five ( 5) ways package com.gsr.Map; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; public class IteratorWaysInMAP { public static void IteratorUsingEntrySet(Map<Integer,String> courseMap) { Iterator<Entry<Integer,String>> iterator=courseMap.entrySet().iterator(); System.out.println("Iterator Using EntrySet"); while(iterator.hasNext()) { Entry<Integer,String> entry=iterator.next(); System.out.println("Key is : "+entry.getKey()+" and value is "+entry.getValue()); } } public static void IteratorUsingKeySet(Map<Integer,String> courseMap) { Iterator<Integer> iterator=courseMap.keySet().iterator(); System.out.println("Iterator Using KeySet"); while(iterator.hasNext()) { Integer key=iterator.next(); System.out.println("Key is : " +key+" and value is "...