Wednesday, February 17, 2016

Merge Two Strings and Pick Distinct

Take 2 strings s1 and s2 including only letters from a to z. Return a new sorted string, the longest possible, containing distinct letters, - each taken only once - coming from s1 or s2.

Example:


a = "xyaabbbccccdefww"
b = "xxxxyyyyabklmopq"
longest(a, b) -> "abcdefklmopqwxy"

a = "abcdefghijklmnopqrstuvwxyz"
longest(a, a) -> "abcdefghijklmnopqrstuvwxyz" 

Saturday, November 30, 2013

Java Program 011

The U.S. Census Bureau projects population based on the following assumptions:

One birth every 7 seconds
One death every 13 seconds
One new immigrant every 45 seconds

Write a program to display the population for each of the next five years. Assume the current population is 312,032,486 and one year has 365 days. Hint: In Java, if two integers perform division, the result is an integer. The fraction part is truncated.

For example, 5/ 4 is 1 (not 1.25) and 10 / 4 is 2 (not 2.5).

Saturday, November 23, 2013

Interview Questions

Our Java questions and answers focus on all areas of Java programming language covering 350+ topics in Java. These topics and Questions are taken from Mr. Shashi Kumar from SSSIT, KPHB, Hyderabad-72.

You can contact him Through SSSIT from here <Link>

Highlights
- Interview Questions Faced by Mr. Shashi Kumar
- Questions & Answers in Java with explanations
- Every MCQ set focuses on a specific topic in Java Language
Let’s Get Started & Continue Reading…………………………….

JAVA .NET FAQ’S

Also see our user generated FAQ on the wiki.

1. What is java.net?

java.net is a premier web-based, open community created to facilitate Java™ technology collaboration in applied areas of technology and industry solutions. java.net is a central gathering place for Java technology enthusiasts and existing communities across industries, platforms, and interest groups.

2. What is the goal of java.net?

The goal is to expand the Java™ technology portfolio of applications, tools, and services by promoting conversation and collaboration around development of practical applications across industry groups.

Continue reading………..

Monday, September 16, 2013

Java Program 010

Write a program DisplayPattern2.java, which accepts a number as argument and print the following output:

Ex. Input : 5

Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

public class DisplayPattern2
{
    public static void main(String args[])
    {
        int end = Integer.parseInt(args[0]);
        for(int i = 1; i <= end; i++)
        {
            for(int j = 1; j <= i; j++)
                System.out.print(j + " ");
            System.out.println("");
        }
    }
}

Wednesday, September 11, 2013

Java Program 009

Create a file ArithmeticTest.java which accepts three arguments- two int values and one Operator (any one of +, –, *) and Print The Following Output:

Output: 2 + 3 = 5

 

// Code NOT Tested !!

public class AdditionTest{
	public static void main(String[] args){
		int n1 = Integer.parseInt(args[0]);
		int n2 = Integer.parseInt(args[1]);
		String operator = args[2];
		
		if (operator.equals("*"))
			System.out.println(n1 + " * " + n2 + " = " + (n1 * n2));
		else if (operator.equals("+"))
			System.out.println(n1 + " + " + n2 + " = " + (n1 + n2));
		else if (operator.equals("-"))
			System.out.println(n1 + " - " + n2 + " = " + (n1 - n2));
		else
			System.out.println(" Use a Correct Third Operator");
		
		System.out.println(" Bye,");
	}
}		

Blogger Labels: Java,Program,ArithmeticTest,arguments,Operator,Print

Java Program 008

Write a program TestDemo.java which accepts the number as argument and print ” You Have Entered Zero ” if the Value is equal to 0. It should print “You have entered Positive value ” if the value is greater than 0. It should print “You have entered negative value ” if the Value is less than Zero.

public class TestDemo
{
	public static void main(String[] args)
	{
		int n1 = Integer.parseInt(args[0]);
		if(n1 == 0)
			System.out.println("You have entered ZERO ");
		else if (n1 < 0)
			System.out.println("You have entered Negetive value ");
		else 
			System.out.println("You have entered positive value ");
	}
}
Blogger Labels: Simple codes,Java,Program,argument