Skip to main content

Posts

Play febnocci and factorial on BigNumbers ...

BigNumberOperations.java --------------------------------------------- package com.blogspot.developerssbrain; import java.math.BigDecimal; public class BigNumberOperations {     static BigDecimal factorial(int n){         BigDecimal fact=new BigDecimal("1");         while(n>0){             fact=fact.multiply(new BigDecimal(n));             n--;         }         return fact;     }         static BigDecimal febnocci(int n){         BigDecimal i=new BigDecimal("1");         BigDecimal j=new BigDecimal("1");         while(n-2>0){             j=j.add(i);      ...

Nested Classes

OuterClass.java ------------------------------------------------------------ package org.developerssolutions; public class OuterClass {     public void method(){         System.out.println("OuterClass.Method1");     }         class InnerClass{         public void method(){             System.out.println("OuterClass.InnerClass.Method1");         }         class InnerInnerClass{             public void method(){                 System.out.println("OuterClass.InnerClass.InnerInnerClass.Method1");             }         }     }     } Test.java ---------------...

Web Client to print weather report for the input City and Country

Java program to print weather report Steps: 1.Download the WSDL file from the URL http://www.webservicex.net/globalweather.asmx?WSDL 2.Create a java project in Eclipse 3.Copy the WSDL file to java project 4.Expand the java project in Eclipse and right click on the WSDL file and generate webservice client 5.Rename the package name into your source folder to your desired name 6.Add the following Main Class to your package Main.java package org.susil.solutions; import java.io.IOException; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.CharacterData; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class Main {     public static String getCharacterDataFromElement(Element e) {     ...

Find whose best friends got offered higher salary!

Problem Statement You are given three tables:  Students ,  Friends  and  Packages.   Students   contains two columns: ID  and   Name .   Friends   contains two columns:   ID   and   Friend_ID   ( ID   of the ONLY best friend). Packages  contains two columns:   ID   and   Salary   (offered salary in $ thousands per month). Write a query to output the names of those students whose best friends got offered a higher salary than them. Names must be ordered by the salary amount offered to the best friends. It is guaranteed that no two students got same salary offer. Sample Input Sample Output Samantha Julia Scarlet Explanation See the following table: Now, ·          Samantha's   best friend got offered a higher salary than her at 11.55 ·          J...

MinAbsSumOfTwo ::: Find the minimal absolute value of a sum of two elements.

Task description Let A be a non-empty zero-indexed array consisting of N integers. The  abs sum of two  for a pair of indices (P, Q) is the absolute value |A[P] + A[Q]|, for 0 ≤ P ≤ Q < N. For example, the following array A: A[0] = 1 A[1] = 4 A[2] = -3 has pairs of indices (0, 0), (0, 1), (0, 2), (1, 1), (1, 2), (2, 2). The abs sum of two for the pair (0, 0) is A[0] + A[0] = |1 + 1| = 2. The abs sum of two for the pair (0, 1) is A[0] + A[1] = |1 + 4| = 5. The abs sum of two for the pair (0, 2) is A[0] + A[2] = |1 + (−3)| = 2. The abs sum of two for the pair (1, 1) is A[1] + A[1] = |4 + 4| = 8. The abs sum of two for the pair (1, 2) is A[1] + A[2] = |4 + (−3)| = 1. The abs sum of two for the pair (2, 2) is A[2] + A[2] = |(−3) + (−3)| = 6. Write a function: class Solution { public int solution(int[] A); } that, given a non-empty zero-indexed array A consisting of N integers, returns the minimal abs sum of two for any pair of indices in this array. For e...

COMPUTE number of inversion in an array - ArrayInversionCount

Task description A zero-indexed array A consisting of N integers is given. An  inversion is a pair of indexes (P, Q) such that P < Q and A[Q] < A[P]. Write a function: class Solution { public int solution(int[] A); } that COMPUTES  the number of inversions in A, or returns −1 if it exceeds 1,000,000,000. Assume that: N is an integer within the range [ 0 .. 100,000 ]; each element of array A is an integer within the range [ −2,147,483,648 .. 2,147,483,647 ]. For example, in the following array: A[0] = -1 A[1] = 6 A[2] = 3 A[3] = 4 A[4] = 7 A[5] = 4 there are four inversions: (1,2) (1,3) (1,5) (4,5) so the function should return 4. Complexity: expected worst-case time complexity is O(N*log(N)); expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments). Elements of input arrays can be modified. // you can also use imports, for example: // import java.util.*; // you can...