>

Friday, December 7, 2012

String Replace in Java

Most of us know that replace function in  String is only works with characters. As work within single quotes.. But String replace function also works fine with double quotes.

public class StringManipulation {

    public static void main(String args[]){

        String name="commission";
        name=name.replace("i","j");
        System.out.println(name);
    }
}


OUTPUT

commjssjon

Sequence Labelling a New Technology

SEQUENCE LABELING:

Sequence labeling is a technology where appliances in our home will interactive with us. Means they will listen our commands and take action based on commands. In addition with predefined algorithms. And  reduce the workload for housewives, senior citizens, disabled persons. But in out of box it will be increase our laziness. Because now a days people are forgot to walk. Most people will not walk even 30 minutes per day.

Smart homes, or homes wherein appliances are turned on or off with direction from us — either pre-loaded cues, or through speech recognition — already exist. Apparently, these technologies are based on a process called sequence labelling, which classifies how tasks occur in a consequential sequence.

For more details visit the
http://www.thehindu.com/sci-tech/technology/towards-a-smart-home/article4156967.ece

An article from Hindu.,.. 

 

Friday, November 9, 2012

Java Program without Semicolon

 class Program
{
public static void main( String[] args )
{
 if( System.out.printf( "India not poor country%n" )== null ){
 }
}}

OUTPUT:
India not poor country

Factorial Using While loop in java

import java.util.Scanner;

class FactorialWhile{

 public static void main(String args[]){

    int fact=1,num,i=1;

    System.out.println("Enter the number:");

   Scanner in=new Scanner(System.in);

   num=in.nextInt();

  while(i<=num){

    fact=fact*i;

    i++;
}

  System.out.println("factorial of given number is "+fact);
}  }


OUTPUT:

Enter the number:
4
factorial of given number is 24

String Reverse Program in Java Wihtout Reverse Function

import java.util.Scanner;

public class StringReverse {
public static void stringReverse(String name)
{
    String str=name;
    char c[]=str.toCharArray();
        System.out.println("Reversed String : ");
    for(int i=str.length();i>0;i--)
    {
        System.out.print(c[i-1]);

    }
       

       
        }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in=new Scanner(System.in);
        System.out.println("enter your string:");
        String input=in.nextLine();
        System.out.println("Given String Value :"+ input);
        stringReverse(input);
    }

}


OUTPUT:
enter your string:
Kanimozhi
Given String Value :Kanimozhi
Reversed String :
ihzominaK

Swapping Without Third Variable

import java.util.Scanner;
class SwappingNoThird
    {
        public static void  main(String san[])
    {
        int firstNumber,secondNumber;
        Scanner in=new Scanner(System.in);
   
        System.out.println("Enter the first number:");
        firstNumber=in.nextInt();
   
        System.out.println("Enter the second Number :");
        secondNumber=in.nextInt();
   
        System.out.println("Before Swapping two variables  FirstNumber : "  +firstNumber +" Second Number " +secondNumber);
       
        firstNumber=firstNumber+secondNumber;
        secondNumber=firstNumber-secondNumber;
        firstNumber=firstNumber-secondNumber;
       
   
        System.out.println("After  Swapping two variables  FirstNumber : "  +firstNumber +" Second Number " +secondNumber);
    }
    }

OUTPUT:

Enter the first number:
76
Enter the second Number :
67
Before Swapping two variables  FirstNumber : 76 Second Number 67
After  Swapping two variables  FirstNumber : 67 Second Number 76

Swapping Variables with Third Variable

import java.util.Scanner;
class SwappingWithThird
    {
        public static void  main(String san[])
    {
        int firstNumber,secondNumber,temp;
        Scanner in=new Scanner(System.in);// for receiving input from user
   
        System.out.println("Enter the first number:");
        firstNumber=in.nextInt();// get input one
   
        System.out.println("Enter the second Number :");
        secondNumber=in.nextInt(); // get input two
   
        System.out.println("Before Swapping two variables  FirstNumber : "  +firstNumber +" Second Number " +secondNumber);
   
        temp=firstNumber;
        firstNumber=secondNumber;
        secondNumber=firstNumber;
   
        System.out.println("After  Swapping two variables  FirstNumber : "  +firstNumber +" Second Number " +secondNumber);
    }
    }


OUTPUT:

Enter the first number:
6
Enter the second Number :
7
Before Swapping two variables  FirstNumber : 6 Second Number 7
After  Swapping two variables  FirstNumber : 7 Second Number 7