Skip to main content

Posts

Java Int to String Hackerrank Solution

 Java Int to String Hackerrank Solution For Explanation Watch Video: Sample Input 0 100 Sample Output 0 Good job Code: import  java.util.*; import  java.security.*; public   class  Solution {   public   static   void  main(String[] args) {   DoNotTerminate.forbidExit();    try  {    Scanner in =  new  Scanner(System.in);     int  n = in .nextInt();    in.close();     //String s=???; Complete this line below     String s = Integer.toString(n);         if  (n == Integer.parseInt(s)) {     System.out.println( "Good job" );    }  else  {     System.out.println( "Wrong answer." );    }   }  catch  ...

Java Static Initializer Block Hackerrank Solution

 Java Static Initializer Block Hackerrank Solution Sample input 1 1 3 Sample output 1 3 Sample input 2 -1 2 Sample output 2 java.lang.Exception: Breadth and height must be positive Code: import  java.io.*; import  java.util.*; import  java.text.*; import  java.math.*; import  java.util.regex.*; public   class  Solution {      static int B;     static int H;     static boolean flag;     static{         Scanner scn = new Scanner(System.in);         B = scn.nextInt();         H = scn.nextInt();         flag = true;         if(B<=0 || H<=0){       ...

Nested Lists Hackerrank Solution Python

 Nested Lists Hackerrank Solution Python For Explanation Watch Video: Sample Input 0 5 Harry 37.21 Berry 37.21 Tina 37.2 Akriti 41 Harsh 39 Sample Output 0 Berry Harry Code: if  __name__ ==  '__main__' :     emptyDict = {}      def  add(key, value):          emptyDict[key] = value       for  _  in   range ( int ( input ())):         name =  input ()         score =  float ( input ())         add(name,score)     v = emptyDict.values()     second =  ( sorted ( list (( set (v))))[ 1 ])     second_lowest = []      for  key,value  in  emptyDic...

String Validators Hackerrank Solution Python

 String Validators Hackerrank Solution Python For Explanation Watch Video: Sample Input qA2 Sample Output True True True True True Code: if  __name__ ==  '__main__' :     s =  input ()      print(any(c.isalnum() for c in s))     print(any(c.isalpha() for c in s))     print(any(c.isdigit() for c in s))     print(any(c.islower() for c in s))     print(any(c.isupper() for c in s))

Find the Runner-Up Score! Hackerrank Solution Pyhton

 Find the Runner-Up Score! Hackerrank  For Explanation Watch video: Sample Input 0 5 2 3 6 6 5 Sample Output 0 5 Code: if  __name__ ==  '__main__' :     n =  int ( input ())     arr =  map ( int ,  input ().split())      print(sorted(list(set(arr)))[-2])

Java Exception Handling Hackerrank solution

 Java Exception Handling Hackerrank solution For Explanation Watch Video: Sample Input 0 3 5 2 4 0 0 -1 -2 -1 3 Sample Output 0 243 16 java.lang.Exception: n and p should not be zero. java.lang.Exception: n or p should not be negative. java.lang.Exception: n or p should not be negative. Code: import  java.util.Scanner; class  MyCalculator {      /*     * Create the method long power(int, int) here.     */      public long power(int n,int p)throws Exception{         if(n<0 || p<0){             throw new Exception("n or p should not be negative.");         }else if(n==0 && p==0){     ...

Java Varargs - Simple Addition Hackerrank Solution

 Java Varargs - Simple Addition Hackerrank Solution For Explanation Watch Video: Sample Input 1 2 3 4 5 6 Sample Output 1+2=3 1+2+3=6 1+2+3+4+5=15 1+2+3+4+5+6=21 Code: import  java.io.*; import  java.lang.reflect.*; import  java.util.*; import  java.text.*; import  java.math.*; import  java.util.regex.*; class Add{     public static void add(int... arr){         int sum = 0;         for(int i=0;i<arr.length-1;i++){             System.out.print(arr[i]+"+");             sum += arr[i];         }         sum += arr[arr.length-1];         System.out.print(a...