Thursday, September 26

Multiplication table generation using Java (natural numbers up to 20)

Hi ALL,

I wrote a program for Multiplication table generation using java looping concept (natural numbers up to 20).

public class tables{ 

public static void main(String args[])
 {    
   
    for(int i = 1; i <=20; i++) {
        System.out.println("\n\n"+i +" table\n");
        for(int j = 1; j <= 20; j++) {
            System.out.println(j+" *"+i+" ="+(i*j));
        }               
    }
    
 }

}


OUTPUT:

1 table

1 *1 =1
2 *1 =2
3 *1 =3
4 *1 =4
5 *1 =5
6 *1 =6
7 *1 =7
8 *1 =8
9 *1 =9
10 *1 =10
11 *1 =11
12 *1 =12
13 *1 =13
14 *1 =14
15 *1 =15
16 *1 =16
17 *1 =17
18 *1 =18
19 *1 =19
20 *1 =20


2 table

1 *2 =2
2 *2 =4
3 *2 =6
4 *2 =8
5 *2 =10
6 *2 =12
7 *2 =14
8 *2 =16
9 *2 =18
10 *2 =20
11 *2 =22
12 *2 =24
13 *2 =26
14 *2 =28
15 *2 =30
16 *2 =32
17 *2 =34
18 *2 =36
19 *2 =38
20 *2 =40


3 table

1 *3 =3
2 *3 =6
3 *3 =9
4 *3 =12
5 *3 =15
6 *3 =18
7 *3 =21
8 *3 =24
9 *3 =27
10 *3 =30
11 *3 =33
12 *3 =36
13 *3 =39
14 *3 =42
15 *3 =45
16 *3 =48
17 *3 =51
18 *3 =54
19 *3 =57
20 *3 =60


4 table

1 *4 =4
2 *4 =8
3 *4 =12
4 *4 =16
5 *4 =20
6 *4 =24
7 *4 =28
8 *4 =32
9 *4 =36
10 *4 =40
11 *4 =44
12 *4 =48
13 *4 =52
14 *4 =56
15 *4 =60
16 *4 =64
17 *4 =68
18 *4 =72
19 *4 =76
20 *4 =80


5 table

1 *5 =5
2 *5 =10
3 *5 =15
4 *5 =20
5 *5 =25
6 *5 =30
7 *5 =35
8 *5 =40
9 *5 =45
10 *5 =50
11 *5 =55
12 *5 =60
13 *5 =65
14 *5 =70
15 *5 =75
16 *5 =80
17 *5 =85
18 *5 =90
19 *5 =95
20 *5 =100

etc upto 20th table


Wednesday, September 25

String Class & String manipulation in Java Part-3( Simple Examples for startsWith(),lastIndexOf(),replace(),replaceAll(),replaceFirst(),split() ,hashCode() Methods)

Hi All,

Here I wrote the program for String Class & String manipulation in java using simple examples :)

/* 

startsWith() Method

lastIndexOf() Method

replace() Method 

replaceAll() Method 

replaceFirst() Method 

split() Method 

hashCode() Method

*/

 

import java.lang.String.*;
import java.io.*;
public class stringOperations3 {
    public static void main(String args[]){
       /*String Manipuldation Part-3*/
        
        /* String lastIndexOf() Method
         *  
         * Note:
            1. int lastIndexOf(int ch): Returns the index within this string of the last occurrence of the specified character or -1 if the character does not occur.
            2. public int lastIndexOf(int ch, int fromIndex): Returns the index of the last occurrence of the character in the character sequence represented by this
               object that is less than or equal to fromIndex, or -1 if the character does not occur before that point.
            3. public int lastIndexOf(String str): If the string argument occurs one or more times as a substring within this object,
               then it returns the index of the first character of the last such substring is returned. If it does not occur as a substring, -1 is returned.
            4. public int lastIndexOf(String str, int fromIndex): Returns the index within this string of the last occurrence of the specified substring,
               searching backward starting at the specified index.
         */
        String name="SKI Technology in Technopark";
        String cName="no";
        System.out.println("Result of lastIndexOf(int ch) Method :"+name.lastIndexOf('T'));
        System.out.println("Result of lastIndexOf(int ch, int fromIndex) Method :"+name.lastIndexOf('T',4));
        System.out.println("Result of lastIndexOf(String str) Method :"+name.lastIndexOf(cName));
        System.out.println("Result of astIndexOf(String str, int fromIndex)Method :"+name.lastIndexOf(cName,15));
       
        
        /* replace() Method
         *
         * Note: It returns a string derived from this string by replacing every occurrence of oldChar with newChar.
         */
        String val=new String("My Name is skitech");       
        System.out.println("Result of the replace() Method :"+val.replace('s', 'k'));
        System.out.println("Result of the replace() Method :"+val.replace('k', 's'));
        
        /*replaceAll() Method
         *
         * Note: This method replaces each substring of this string that matches the given regular expression with the given replacement.
         */
        String cname="SkiTECH is fantastic";
        System.out.println("Result of the replaceAll() Method :"+cname.replaceAll("SkiTECH","Salem"));
        System.out.println("Result of the replaceAll() Method :"+cname.replaceAll("(.*)is(.*)","Salem"));
        
        /* replaceFirst() Method
         *
         * Note: This method replaces the first substring of this string that matches the given regular expression with the given replacement.
         */
        String cname1="my company name is Skitech in chennai company";
        System.out.println("Result of the replaceFirst() Method :"+cname1.replaceFirst(cname1,"bala"));
        System.out.println("Result of the replaceFirst() Method1 :"+cname1.replaceFirst("company","COMPANY"));
        System.out.println("Result of the replaceFirst() Method2 :"+cname1.replaceFirst("(.*)company(.*)","Skitech"));
        
        /* split() Method
         *
         * Note: It returns the array of strings computed by splitting this string around matches of the given regular expression.
         */
        System.out.println("Result of split() Method");
        String Str = new String("Welcome=to=SKITECH=blog");        
        for (String res: Str.split("="))
            System.out.println(res);
        
        System.out.println("Result of split() Method1");
        for(String res1:Str.split("=", 3))
             System.out.println(res1);
        
        System.out.println("Result of split() Method2");
        for(String res2:Str.split("=", 2))
             System.out.println(res2);
                   
        /*  startsWith() Method
         *
         * Note: It returns true if the character sequence represented by the argument is a prefix of the character sequence represented by this string; false otherwise.
         */
        String temp1="welcome to the SKiTECH";
        System.out.println("Result of startsWith() Method "+temp1.startsWith("welcome"));
        System.out.println("Result of startsWith() Method1 "+temp1.startsWith("to"));
        System.out.println("Result of startsWith() Method2 "+temp1.startsWith("the",11));
        
        /* hashCode() Method
         *
         * Note: This method returns a hash code value for this object.           
         */
        String str1="Ski technology in technopark";       
        System.out.println("Result of hashCode() Method "+str1.hashCode());
    }
    
}

 OUTPUT:


Result of lastIndexOf(int ch) Method :18
Result of lastIndexOf(int ch, int fromIndex) Method :4
Result of lastIndexOf(String str) Method :22
Result of astIndexOf(String str, int fromIndex)Method :8
Result of the replace() Method :My Name ik kkitech
Result of the replace() Method :My Name is ssitech
Result of the replaceAll() Method :Salem is fantastic
Result of the replaceAll() Method :Salem
Result of the replaceFirst() Method :bala
Result of the replaceFirst() Method1 :my COMPANY name is Skitech in chennai company
Result of the replaceFirst() Method2 :Skitech
Result of split() Method
Welcome
to
SKITECH
blog
Result of split() Method1
Welcome
to
SKITECH=blog
Result of split() Method2
Welcome
to=SKITECH=blog
Result of startsWith() Method true
Result of startsWith() Method1 false
Result of startsWith() Method2 true
Result of hashCode() Method 1464026455


String Class & String manipulation in Java Part-2( Simple Examples for substring(),toCharArray(),toLowerCase(),toUpperCase(),toString(),integer to string in java, double to string in java,trim(),indexOf(),intern() Methods )

Hi All,

Here I wrote the program for String Class & String manipulation in java using simple examples :)

  /*

substring() Method

toCharArray() Method

toLowerCase() Method 

toUpperCase() Method 

toString() Method 

integer to string in java 

double to string in java  

trim() Method 

indexOf() Method 

intern() Method 

*/

import java.lang.String.*; 

public class stringOperations2 {
    public static void main(String args[]){
       /*String Manipuldation Part-2*/
       
        /* String substring() Method
         * 
         * Note: The substring begins with the character at the specified index and extends to the end of this string or up to endIndex - 1 if second argument is given.
         */
        String name="SKI Technology";
        String cName=name.substring(0,8);
        System.out.println("CName value in substring() Method :"+cName);
        String cName1=name.substring(4);
        System.out.println("CName1 value is substring() Method (No EndIndex it will take upto endIndex - 1 if second argument is given): "+cName1);
       
        /*  toCharArray() Method
         *
         * Note: This method converts this string to a new character array.
         */
        String val=new String("My Name is SkiTECH");
        char[] b=val.toCharArray();
        System.out.print("Result of the toCharArray() Method ");
        for(char temp: b){
       System.out.print(temp);
    }
       
        /*  String toLowerCase() Method
         *
         * Note: It returns the String, converted to lowercase.
         */
        String cname="SkiTECH";
        System.out.println("\nResult of the String toLowerCase() Method "+cname.toLowerCase());
       
        /* String toUpperCase() Method
         *
         * Note: It returns the String, converted to uppercase.
         */
        String cname1="skitech";
        System.out.println("Result of the String toUpperCase() Method "+cname1.toUpperCase());
       
        /*  toString() Method
         *
         * Note: This method returns the string itself.
         */
        String tname=new String("welcome");
        System.out.println("Result of the toString() Method "+tname.toString());
       
        /*  integer to string in java using toString() method */
        int n=10;
        String sval=Integer.toString(n);
        System.out.println("Integer to string using toString() Method "+sval);
       
        /* double to string in java using toString() method */
        double aDouble = 0.11;
        String sval1 = Double.toString(aDouble);
        System.out.println("Double to string using toString() Method "+sval1);
       
        /*  trim() Method
         *
         * Note: It returns a copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space.
         */
        String temp1=" welcome to the SKiTECH          ";
        System.out.println("Result of the trim() Method "+temp1.trim());
       
        /*  indexOf() Method
         *
         * Note:
           1. public int indexOf(int ch): Returns the index within this string of the first occurrence of the specified character or -1 if the character does not occur.
           2. public int indexOf(int ch, int fromIndex): Returns the index within this string of the first occurrence of the specified character, starting the search at
              the specified index or -1 if the character does not occur.
           3. int indexOf(String str): Returns the index within this string of the first occurrence of the specified substring. If it does not occur as a substring, -1 is returned.
           4. int indexOf(String str, int fromIndex): Returns the index within this string of the first occurrence of the specified substring,
              starting at the specified index. If it does not occur, -1 is returned.
         */
        String str1="Ski technology in technopark";
        String str2="tech";
        System.out.println("Result of indexOf(int ch) method "+str1.indexOf('t'));
        System.out.println("Result of indexOf(int ch, int fromIndex) method "+str1.indexOf('o',13));
        System.out.println("Result of indexOf(String str) method "+str1.indexOf(str2));
        System.out.println("Result of indexOf(String str, int fromIndex) method "+str1.indexOf(str2, 10));
       
        /*  intern() Method
         *
         * Note: This method Returns a canonical representation for the string object.
         */
        String str3="welcome To Skitech";
        System.out.println("Result of the intern() Method "+str3.intern());
    }
   
}

  OUTPUT:

CName value in substring() Method :SKI Tech
CName1 value is substring() Method (No EndIndex it will take upto endIndex - 1 if second argument is given): Technology
Result of the toCharArray() Method My Name is SkiTECH
Result of the String toLowerCase() Method skitech
Result of the String toUpperCase() Method SKITECH
Result of the toString() Method welcome
Integer to string using toString() Method 10
Double to string using toString() Method 0.11
Result of the trim() Method welcome to the SKiTECH
Result of indexOf(int ch) method 4
Result of indexOf(int ch, int fromIndex) method 23
Result of indexOf(String str) method 4
Result of indexOf(String str, int fromIndex) method 18
Result of the intern() Method welcome To Skitech

Wednesday, September 18

String Class & String manipulation in Java Part-1( Simple Examples for Character array values in String,Length Method,Concatenating Method,charAt(),compareTo(),compareToIgnoreCase(),contentEquals() Methods )

Hi All,

Here I wrote the program for String Class & String manipulation in java using simple examples :)

/*

character array values in String

Length Method 

Concatenating Method 

charAt() Method 

compareTo() Method 

compareToIgnoreCase() Method 

contentEquals() Method 

*/

import java.lang.String.*;

public class stringOperations {
    public static void main(String args[]){
        /* Using character array values in String method*/
       
        char[] var1={'a','b','c','d'};
        String val=new String(var1);
        System.out.println("character array values  :" + val);
       
        /* Length Method
         *
         * Note: It used to finding Length of the string values
         */

       
        String statement="Welcome to the string method";
        System.out.println("Length of the statement string  is "+statement.length());
       
        /*  Concatenating Method
         * 
         * Note: This method appends one String to the end of another String.
         */

        String fname="SKi";
        String lname="TECH";
        String username=fname.concat(lname);
        System.out.println("Concatenation of the Strings "+username);
       
        /*  charAt() Method
         *
         * Note: This method returns the character located at the String's specified index. The string indexes start from zero.
         */

       
        String statement1="Welcome to the string method";
        char res=statement1.charAt(11);
        System.out.println("The specified index of String is "+ res);
       
        /*  compareTo() Method
         *
         *  There are two variants of this method. First method compares this String to another Object and second method compares two strings lexicographically.
         *  Note: 
         *  Less than zero (<0)         The invoking string is less than string.
            Greater than zero (>0)    The invoking string is greater than string.
            Zero (0)                    The two strings are equal. 

         */

        String small_name="skitech";
        String uppername="SKITECH";
        String name="SKITECH";
        int result=small_name.compareTo(uppername);
        System.out.println("Result of compareTo method "+result);
        int result1=uppername.compareTo(name);
        System.out.println("Reault1 of compareTo method "+result1);
       
        /* compareToIgnoreCase() Method
         *
         * Note: This method compares two strings lexicographically, ignoring case differences.
         */

        int result2=small_name.compareToIgnoreCase(uppername);
        System.out.println("Result2 of compareToIgnoreCase method (ignoring case differences) "+result2);
        int result3=uppername.compareToIgnoreCase(name);
        System.out.println("Result3 of compareToIgnoreCase mathod (ignoring case differences) "+result3);
       
        /* contentEquals() Method
         *
         * Note: This method returns true if and only if this String represents the same sequence of characters as the specified in StringBuffer(Equally same), otherwise false.
         */

        String findstring="Skitech";
        StringBuffer statement4=new StringBuffer("Skitech Corporation is an Indian software corporation headquartered in Chennai, "
                + " that develops, manufactures, licenses, and supports a wide range of products and services related to computing. "
                + " The company was founded by Balamurugan and Sri on April 1, 2010. "
                + " Skitech is the world's largest software maker ");
        StringBuffer statement5=new StringBuffer("Skitech");
        Boolean content1=findstring.contentEquals(statement4);
        System.out.println("Content1 contentEquals() Method is  "+content1);
        boolean content2=findstring.contentEquals(statement5);
        System.out.println("Content2  contentEquals() Method is "+content2);
    }
   
}


output:

character array values  :abcd
Length of the statement string  is 28
Concatenation of the Strings SKiTECH
The specified index of String is t
Result of compareTo method 32
Reault1 of compareTo method 0
Result2 of compareToIgnoreCase method (ignoring case differences) 0
Result3 of compareToIgnoreCase mathod (ignoring case differences) 0
Content1 contentEquals() Method is  false
Content2  contentEquals() Method is true

Backup files to google drive using PHP coding

 Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...