Skip to main content

Posts

Showing posts from September, 2021

Sherlock and Squares Hackerrank Solution - java

Sherlock and Squares Hackerrank Solution - java For explanation watch video :: Code:: import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.function.*; import  java.util.regex.*; import  java.util.stream.*; import   static  java.util.stream.Collectors.joining; import   static  java.util.stream.Collectors.toList; class  Result {      public   static   int  squares( int  a,  int  b) {          int  first = ( int )Math.ceil(Math.sqrt(a));          int  last = ( int )Math.floor(Math.sqrt(b));          return  last - first + 1 ;     } } public   class  Solution ...

JDBC Program to access table data from mysql database

 import java.sql.*; class MysqlCon  { public static void main(String[] args)  { try{ Connection con = DriverManager.getConnection("jdbc:mysql:///new","root","root"); Statement st = con.createStatement(); String query = "select * from login"; ResultSet rs = st.executeQuery(query); while(rs.next()){ System.out.println(rs.getString(1)+" "+rs.getString(2)); } con.close(); }catch(SQLException e){ System.out.println("Error"); }catch(Exception e){ } } }

A Very Big Sum Hackerrank Solution - java

 A Very Big Sum Hackerrank Solution - java for explanation watch video : Code:: import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; class Result {     /*      * Complete the 'aVeryBigSum' function below.      *      * The function is expected to return a LONG_INTEGER.      * The function accepts LONG_INTEGER_ARRAY ar as parameter.      */     public static long aVeryBigSum(List<Long> ar) {         long sum = 0;         for(int i=0;i<ar.size();i++){             sum = sum + ar.get(i);         }         return sum; ...

Diagonal Difference Hackerrank Solution - java

 Diagonal Difference Hackerrank Solution - java for explanation watch video : Code: import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.function.*; import  java.util.regex.*; import  java.util.stream.*; import   static  java.util.stream.Collectors.joining; import   static  java.util.stream.Collectors.toList; class  Result {      /*      * Complete the 'diagonalDifference' function below.      *      * The function is expected to return an INTEGER.      * The function accepts 2D_INTEGER_ARRAY arr as parameter.      */      public   static ...

The Blunder Hackerrank Solution - SQL

 The Blunder Hackerrank Solution - SQL For explanation watch video :: Code: select ceil(avg(salary)-avg(replace(salary,'0',''))) from Employees;

java hashset hackerrank solution - java 15

 java hashset hackerrank solution - java 15 for explanation watch video: code: import  java.io.*; import  java.util.*; public   class  Solution {      public   static   void  main(String[] args) {         Scanner scn =  new  Scanner(System.in);          int  t = scn.nextInt();         scn.nextLine();         HashSet<String> hs =  new  HashSet<>();          for ( int  i= 0 ;i<t;i++){             String s = scn.nextLine();             hs.add(s);            ...

java map hackerrank solution - Java 15

   java map hackerrank solution - Java 15 for explanation watch video : Code: import  java.io.*; import  java.util.*; public   class  Solution {      public   static   void  main(String[] args) {         Scanner scn =  new  Scanner(System.in);          int  n = scn.nextInt();         scn.nextLine();         HashMap<String,Integer> hm =  new  HashMap<>();          for ( int  i= 0 ;i<n;i++){             String name = scn.nextLine();              int  mobile = scn.nextInt();    ...

Welcome to Java! hackerrank solution - java

  Welcome to Java! hackerrank solution - java  for explanation watch video: Code: import java.io.*; import java.util.*; public class Solution {     public static void main(String[] args) {        System.out.println("Hello, World.");         System.out.println("Hello, Java.");     } }

Java Stdin and Stdout I hackerrank solution - java

 Java Stdin and Stdout I hackerrank solution - java  for explanation watch video: Code: import  java.io.*; import  java.util.*; public   class  Solution {      public   static   void  main(String[] args) {         Scanner scn =  new  Scanner(System.in);          int  a = scn.nextInt();          int  b = scn.nextInt();          int  c = scn.nextInt();         System.out.println(a);         System.out.println(b);         System.out.println(c);     } }

Java Varargs - Simple Addition hackerrank Solution - Java

 Java Varargs - Simple Addition hackerrank Solution - Java  for explanation watch video : Code: import  java.io.*; import  java.util.*; public   class  Solution {      public   static   void  add( int ... arr){          int  sum =  0 ;          for ( int  i= 0 ;i<arr.length;i++){             sum = sum + arr[i];              if (i==arr.length- 1 ){                 System.out.print(arr[i]+ "=" );             } else {                 System.out.print(arr[i]+ "+"...

Maximum Perimeter Triangle Hackerrank Solution - java

 Maximum Perimeter Triangle Hackerrank Solution - java  For Explanation watch video : Code: import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.function.*; import  java.util.regex.*; import  java.util.stream.*; import   static  java.util.stream.Collectors.joining; import   static  java.util.stream.Collectors.toList; class  Result {      /*      * Complete the 'maximumPerimeterTriangle' function below.      *      * The function is expected to return an INTEGER_ARRAY.      * The function accepts INTEGER_ARRAY sticks as parameter.      */    ...

Weather Observation Station 13 Hackerrank Solution - SQL

 Weather Observation Station 13 Hackerrank Solution - SQL For Explanation Watch Video :  Code : select round(sum(LAT_N),4) from station where LAT_N > 38.7880 and LAT_N < 137.2345;

Top Earners Hackerrank Solution - SQL | Hackerrank SQL

 Top Earners Hackerrank Solution - SQL for explanation watch video : Code :: select max(salary * months ),count(*) from Employee where salary*months = (select max(salary*months) from Employee);

Grid Challenge Hackerrank Solution - java | Hackerrank Algorithm

 Grid Challenge Hackerrank Solution - java  For Explanation Watch Video :: Code :: import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.function.*; import  java.util.regex.*; import  java.util.stream.*; import   static  java.util.stream.Collectors.joining; import   static  java.util.stream.Collectors.toList; class  Result {           public   static  String sort(String s){          char [] ch = s.toCharArray();         Arrays.sort(ch);          return   new  String(ch);     }      public   static  String gridChallenge(List<String> grid...

Two Strings Hackerrank Solution - java

 Two Strings Hackerrank Solution - java  For explanation watch video :: Code :: import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; class Result {     /*      * Complete the 'twoStrings' function below.      *      * The function is expected to return a STRING.      * The function accepts following parameters:      *  1. STRING s1      *  2. STRING s2      */     public static String twoStrings(String s1, String s2) {         HashSet<Character> hs = new HashSet<>();         for(Character ch : s1.toCharArray()){       ...

Marc's Cakewalk Hackerrank Solution - Java | Hackerrank Algorithms

 Marc's Cakewalk Hackerrank Solution - Java  For Explanation watch video : Code : import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.function.*; import  java.util.regex.*; import  java.util.stream.*; import   static  java.util.stream.Collectors.joining; import   static  java.util.stream.Collectors.toList; class  Result {      /*      * Complete the 'marcsCakewalk' function below.      *      * The function is expected to return a LONG_INTEGER.      * The function accepts INTEGER_ARRAY calorie as parameter.      */      public   static...

Sum and Difference of Two Numbers Hackerrank Solution - C Language

 Sum and Difference of Two Numbers Hackerrank Solution - C Language  Code: #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main() {      int  a,b;      float  c,d;     scanf( "%d %d %f %f" ,&a,&b,&c,&d);      int  sum1 = a+b;      int  diff1 = a-b;      float  sum2 = c+d;      float  diff2 = c-d;     printf( "%d %d\n" ,sum1,diff1);     printf( "%.1f %.1f" ,sum2,diff2);      return   0 ; }

Conditional Statements in C Hackerrank Solution - C Language

 Conditional Statements in C Hackerrank Solution - C Language Code: #include   < assert.h > #include   < limits.h > #include   < math.h > #include   < stdbool.h > #include   < stddef.h > #include   < stdint.h > #include   < stdio.h > #include   < stdlib.h > #include   < string.h > char * readline(); int  main() {      char * n_endptr;      char * n_str = readline();      int  n = strtol(n_str, &n_endptr,  10 );      if  (n_endptr == n_str || *n_endptr !=  ' \ 0 ' ) { exit(EXIT_FAILURE); }      // Write Your Code Here      if (n== 1 ){         printf( "one" );     } else   if (...

1D Arrays in C Hackerrank Solution - C Language

  1D Arrays in C Hackerrank Solution - C Language  Code : #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main() {      int  n;     scanf( "%d" ,&n);      int  arr[n];      int  sum =  0 ;      for ( int  i= 0 ;i<n;i++){         scanf( "%d" ,&arr[i]);         sum = sum + arr[i];     }       printf( "%d" ,sum);      return   0 ; }

Print the Elements of a Linked List Hackerrank Solution - java

 Print the Elements of a Linked List Hackerrank Solution - java For Explanation Watch Video : code: import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.regex.*; public   class  Solution {      static   class  SinglyLinkedListNode {          public   int  data;          public  SinglyLinkedListNode next;          public  SinglyLinkedListNode( int  nodeData) {              this .data = nodeData;              this .next = null;         }     }  ...

Print in Reverse Hackerrank Solution - java

 Print in Reverse Hackerrank Solution - java For Explanation Watch Video: Code: import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.regex.*; public   class  Solution {      static   class  SinglyLinkedListNode {          public   int  data;          public  SinglyLinkedListNode next;          public  SinglyLinkedListNode( int  nodeData) {              this .data = nodeData;              this .next = null;         }     }      s...

For Loop in C Hackerrank Solution - C Language

 For Loop in C Hackerrank Solution - C Language Code: #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main()  {      int  a, b;     scanf( "%d\n%d" , &a, &b);      for ( int  i=a;i<=b;i++){       if (i>= 1  && i<= 9 ){           if (i== 1 ){              printf( "one\n" );          } else   if (i== 2 ){              printf( "two\n" );          } else   if (i== 3 ){              printf( "three\n" ); ...

Sum of Digits of a Five Digit Number Hackerrank Solution - C

 Sum of Digits of a Five Digit Number Hackerrank Solution - C Code : #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int  main() {           int  n;     scanf( "%d" , &n);      //Complete the code to calculate the sum of the five digits on n.      int  sum =  0 ;      while (n!= 0 ){          int  r = n% 10 ;         n = n/ 10 ;         sum = sum + r;     }     printf( "%d" ,sum);      return   0 ; }