Showing posts with label Java Codes. Show all posts
Showing posts with label Java Codes. Show all posts

How to get day month year in date


import java.util.Calendar;

public class GetDate {
    public static void main(String[] args) {

        Calendar ca1 = Calendar.getInstance();

        /// get day month year from set date
        ca1.set(2009, 05, 15); // dont set this date if current date is required

        int iDay=ca1.get(Calendar.DATE);
        int iMonth=ca1.get(Calendar.MONTH); // In Current date Add 1 in month
        int iYear=ca1.get(Calendar.YEAR);

        System.out.println("Day :"+iDay);
        System.out.println("Month :"+iMonth);
        System.out.println("Year :"+iYear);
    }
}
READ MORE - How to get day month year in date

How to find Week of Year


import java.util.Calendar;

public class WeekOfYear {

    public static void main(String[] args) {

        Calendar ca1 = Calendar.getInstance();

        /*
        set(int year, int month, int date)
        Jan=0,Feb=1,Mar=2...
        */
        ca1.set(2009,4,22);

        int WEEK_OF_YEAR=ca1.get(Calendar.WEEK_OF_YEAR);

        System.out.println("WEEK OF YEAR :"+WEEK_OF_YEAR);
    }
}
READ MORE - How to find Week of Year

How to get Day of Week in Month


import java.util.Calendar;

public class DayOfWeekInMonth {

    public static void main(String[] args) {

        Calendar ca1 = Calendar.getInstance();

        ca1.set(2009, 6, 22);

        int DAY_OF_WEEK_IN_MONTH=ca1.get(Calendar.DAY_OF_WEEK_IN_MONTH);

        // More Calendar Date option can check
        /*
        int DAY_OF_MONTH=ca1.get(Calendar.DAY_OF_MONTH);
        int DAY_OF_WEEK=ca1.get(Calendar.DAY_OF_WEEK);
        int DAY_OF_YEAR=ca1.get(Calendar.DAY_OF_YEAR);
        int WEEK_OF_MONTH=ca1.get(Calendar.WEEK_OF_MONTH);
        int WEEK_OF_YEAR=ca1.get(Calendar.WEEK_OF_YEAR);
         */

        System.out.println("DAY OF WEEK IN MONTH :"+DAY_OF_WEEK_IN_MONTH);
    }
}
READ MORE - How to get Day of Week in Month

How to Add or Subtract Date


import java.util.Calendar;

public class AddDate {

    public static void main(String[] args) {

    Calendar ca1 = Calendar.getInstance();
    ca1.set(2009,05,25);

    // Addition of date in java        
    ca1.add(Calendar.DATE, 23); // Add 23 days in Dates in Calendar
    //ca1.add(Calendar.MONTH, 2); // Add 2 Month in Date in Calendar
    //ca1.add(Calendar.YEAR, 4); // Add 4 Year in Date in Calendar

    /*
     *  Subtracting Date in Calendar
     *  
     *  ca1.add(Calendar.DATE, -23); // Subtracting 23 days from date
     *  //ca1.add(Calendar.MONTH, -2); // Subtracting 2 Month in Date in Calendar
     *  //ca1.add(Calendar.YEAR, -4); // Subtracting 4 Year in Date in Calendar
     */

    System.out.println("Date :"+ca1.get(Calendar.DATE));
    System.out.println("Month :"+ca1.get(Calendar.MONTH));
    System.out.println("Year :"+ca1.get(Calendar.YEAR));
    }
}
READ MORE - How to Add or Subtract Date

find Week of Month in java


import java.util.Calendar;

public class WeekOfMonth {

    public static void main(String[] args) {
        Calendar ca1 = Calendar.getInstance();

        /*
        set(int year, int month, int date)
        Jan=0,Feb=1,Mar=2...
        */
        ca1.set(2009,4,22);

        int WEEK_OF_MONTH=ca1.get(Calendar.WEEK_OF_MONTH);
        System.out.println("Week of Month :"+WEEK_OF_MONTH);

        // More Calendar Date option can check
        /*
        int DAY_OF_MONTH=ca1.get(Calendar.DAY_OF_MONTH);
        int DAY_OF_WEEK=ca1.get(Calendar.DAY_OF_WEEK);
        int DAY_OF_YEAR=ca1.get(Calendar.DAY_OF_YEAR);
        int WEEK_OF_YEAR=ca1.get(Calendar.WEEK_OF_YEAR);
        */
    }
}
READ MORE - find Week of Month in java

find Day of Year in Java


import java.util.Calendar;

public class DayOfYear {

    public static void main(String[] args) {
        Calendar ca1 = Calendar.getInstance();

        /*
        set(int year, int month, int date)
        Jan=0,Feb=1,Mar=2...
        */
        ca1.set(2009,4,22);

        /*
        2 Feb 2009, Day of Year, Jan 31 + 2 Feb =33 day of year
        */

        int DAY_OF_YEAR=ca1.get(Calendar.DAY_OF_YEAR);
        System.out.println("Day of Year :"+DAY_OF_YEAR);

        // More Calendar Date option can check
        /*
        int DAY_OF_MONTH=ca1.get(Calendar.DAY_OF_MONTH);
        int DAY_OF_WEEK=ca1.get(Calendar.DAY_OF_WEEK);
        int WEEK_OF_MONTH=ca1.get(Calendar.WEEK_OF_MONTH);
        int WEEK_OF_YEAR=ca1.get(Calendar.WEEK_OF_YEAR);
         */
    }
}
READ MORE - find Day of Year in Java

How to Create file in Java


import java.io.File;
import java.io.FileWriter;
import java.io.BufferedWriter;

public class JavaIOWriteFileExample {

    public static void main(String[] args) {

        File f=new File("c:\\createNewfile.txt");

        try{
            FileWriter fstreamCopy = new FileWriter(f);
            BufferedWriter outobjCopy = new BufferedWriter(fstreamCopy);
            outobjCopy.write("The content write to inside the file");
            outobjCopy.close();
         }
        catch (Exception e){
              e.printStackTrace();
         }
    }
}
READ MORE - How to Create file in Java

List Example in java


import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;

public class ListExample {

    public static void main(String[] args) {

        // List Example implement with ArrayList
        List<String> ls=new ArrayList<String>();

        ls.add("one");
        ls.add("Three");
        ls.add("two");
        ls.add("four");

        Iterator it=ls.iterator();

        while(it.hasNext())
        {
          String value=(String)it.next();

          System.out.println("Value :"+value);
        }
    }
}
READ MORE - List Example in java

Greatest Common Divisor or GCD using Recursion in java


public class GCD
{
    public static int gcd(int num1, int num2)
    {
        if(num2 == 0)
        {
            return num1;
        }
        else
        {
            return gcd(num2, num1%num2);
        }
    }

}

//main class


import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
       Scanner input = new Scanner(System.in);

      System.out.print("Enter the first number: ");
      int num1 = input.nextInt();

      System.out.print("Enter the second power: ");
      int num2 = input.nextInt();

      GCD access = new GCD();

      System.out.print("The GCD of 2 numbers is: " + access.gcd(num1, num2));

    }

}
READ MORE - Greatest Common Divisor or GCD using Recursion in java

Recursive function for X to the power Y


public class Power
{
    public static double power(double base, double basePow)
    {
        
        if(basePow==0)
        {
            return 1;
        }
        else if(basePow==1)
        {
            return base;
        }
        else if(basePow>1)
        {
            return base*power(base,basePow-1);
        }
        else
        {

              return 1/power(base, -1 * basePow);
        }
       
       
    }
    
}

//main class

import java.util.Scanner;

public class Main {

    public static void main(String[] args)
    {
      Scanner input = new Scanner(System.in);

      System.out.print("Enter the base number: ");
      double base = input.nextInt();

      System.out.print("Enter the base power: ");
      double basePow = input.nextInt();

      
      Power access = new Power();
      
      System.out.print(base + " to the power of " + basePow + " is: " + access.power(base, basePow));

    }

}
READ MORE - Recursive function for X to the power Y

Recursive Koch Snow Flakes in java


import java.awt.*;

import javax.swing.*;

public class recursiveKochSnowFlakes extends JApplet{
 int level = 0;

 public void init(){
  String levelStr = JOptionPane.showInputDialog("Enter the depth of recursion");

  level = Integer.parseInt(levelStr);
 }

 public void paint(Graphics g){

  drawSnow(g,level,20,280,280,280);
  drawSnow(g,level,280,280,150,20);
  drawSnow(g,level,150,20,20,280);

 }

 private void drawSnow (Graphics g, int lev, int x1, int y1, int x5, int y5){
       int deltaX, deltaY, x2, y2, x3, y3, x4, y4;

       if (lev == 0){

        g.drawLine(x1, y1, x5, y5);
       }
       else{
         deltaX = x5 - x1;
         deltaY = y5 - y1;

         x2 = x1 + deltaX / 3;
         y2 = y1 + deltaY / 3;

         x3 = (int) (0.5 * (x1+x5) + Math.sqrt(3) * (y1-y5)/6);
         y3 = (int) (0.5 * (y1+y5) + Math.sqrt(3) * (x5-x1)/6);

         x4 = x1 + 2 * deltaX /3;
         y4 = y1 + 2 * deltaY /3;

         drawSnow (g,lev-1, x1, y1, x2, y2);
         drawSnow (g,lev-1, x2, y2, x3, y3);
         drawSnow (g,lev-1, x3, y3, x4, y4);
         drawSnow (g,lev-1, x4, y4, x5, y5);
        }
    }
}
READ MORE - Recursive Koch Snow Flakes in java

Program that will Determine the Person's Salutation and Current Age


public class Person
{
    private String fName;
    private String lName;
    private String sex;
    
    private int year;
    private int month;
    private int day;
    

    public Person()
    {
        fName="";
        lName="";
        sex="";
        
        year=0;
        month=0;
        day=0;
    }
    public Person(String fName1, String lName1, String gender)
    {
        fName=fName1;
        lName=lName1;
        sex=gender;
       
    }
    public String getFName()
    {
        return fName;
    }
    public void setFName(String fName1)
    {
        fName=fName1;
    }
    public String getLName()
    {
        return lName;
    }
    public void setLName(String lName1)
    {
        lName=lName1;
    }
    public String getSex()
    {
        return sex;
    }
    public void setSex(String gender)
    {
        sex=gender;
    }
    public int getYear()
    {
        return year;
    }
    public void setYear(int year1)
    {
        year=year1;
    }
    public int getMonth()
    {
        return month;
    }
    public void setMonth(int month1)
    {
        month=month1;
    }
    public int getDay()
    {
        return day;
    }
    public void setDat(int day1)
    {
        day=day1;
    }
    public String getFullName()
    {
        if(sex.equals("f"))
        {
            return "Ms. "+ fName + " "+lName;
         
        }
        else
        {
           return "Mr. "+ fName +" "+lName;
        }
    }
    public String getAge(int cYear, int cMonth, int cDay, int bYear, int bMonth, int bDay)
    {
        
        String result="";
        int tYear;
        if((cYear>bYear) && (cMonth==bMonth))
        {
            if(cDay==bDay)
            {
               tYear=cYear-bYear;
               result= "Happy " + tYear + "th birthday!";
            }
            else if(cDay>bDay)
            {
               tYear=cYear-bYear;
               result= "Current Age: " + tYear + " years old.";
            }
            else if(cDay<bDay)
            {
                tYear=(cYear-1)-bYear;
               result= "Current Age: " + tYear + " years old.";
            }
        }
        else if((cYear > bYear) && (cMonth > bMonth))
        {
            tYear=cYear-bYear;
            result= "Current Age: " + tYear + " years old.";
        }
        else if((cYear > bYear) && (cMonth < bMonth))
        {
            tYear=(cYear-1)-bYear;
            result= "Current Age: " + tYear + " years old.";
        }
        else if(cYear<bYear)
        {
            result= "Wrong Input. Age Calculation Failed.";
        }
        return result;

    }
            
}


//main class


import java.util.Scanner;


public class Main
{

    
    public static void main(String[] args)
    {

        Scanner input = new Scanner(System.in);

        String fName, lName, gender;
        int cYear, cMonth, cDay;
        int bYear, bMonth, bDay;


        System.out.print("Enter you first name: ");
        fName= input.nextLine();

        System.out.print("Enter you last name: ");
        lName= input.nextLine();

        System.out.print("Enter you Gender: ");
        gender= input.nextLine();


        System.out.print("Please Enter current Date: ");
        cDay= input.nextInt();

        System.out.print("Please Enter current Month: ");
        cMonth= input.nextInt();

        System.out.print("Please Enter current Year: ");
        cYear= input.nextInt();

        System.out.println("-----BIRTHDAY INFORMATION-----");
        System.out.print("Please Enter your Birth Date: ");
        bDay= input.nextInt();

        System.out.print("Please Enter your Birth Month: ");
        bMonth= input.nextInt();

        System.out.print("Please Enter your Birth Year: ");
        bYear= input.nextInt();

        Person access = new Person(fName, lName, gender);
        System.out.println("Name: "+access.getFullName());
        System.out.println(access.getAge(cYear, cMonth, cDay, bYear, bMonth, bDay));
        

    }

}
-----------------------------------
Sample Output 1:
Enter you first name: Johny
Enter you last name: Smith
Enter you Gender: M
Please Enter current Date: 3
Please Enter current Month: 02
Please Enter current Year: 2012
-----BIRTHDAY INFORMATION-----
Please Enter your Birth Date: 3
Please Enter your Birth Month: 02
Please Enter your Birth Year: 1989
READ MORE - Program that will Determine the Person's Salutation and Current Age

Binary Search Using Recursion in java


public class binarySearch
{

    public int binSearch(int[] arr, int fIndex, int lIndex,int search)
    {

int middle = (fIndex + (lIndex - fIndex) / 2);

  if(fIndex<lIndex ){

   if (search == arr[middle]){

    return middle;
   }

   else if(search < arr[middle]){
    if(search == arr[0])
     return 0;
    return binSearch(arr, fIndex, middle, search);
   }

   else if(search > arr[middle]){
    if(search == arr[middle+1])
     return middle + 1;
    return binSearch(arr, middle+1, lIndex, search);
   }

  }
    return -1;
    }

 public void sort(int[] arr)
{
       for(int i=0; i<arr.length; i++)
        {
            for(int j=i+1; j<arr.length; j++ )
            {
                if(arr[i] > arr[j])
                {
                    int temp = arr[j];
                    arr[j]=arr[i];
                    arr[i]= temp;
                }
            }
        }

       for(int i=0; i<arr.length; i++)
       {
           System.out.print(arr[i] + " ");
       }
}

}

//main class


import java.util.Scanner;

public class Main {

    public static void main(String[] args)
    {
         Scanner input = new Scanner(System.in);

        System.out.print("Enter the size of the array: ");
        int n = input.nextInt();
        int[] x = new int[n];

        System.out.print("Enter "+ n +" numbers: ");
        int middle;
        for(int i=0; i<n; i++)
        {
            x[i] = input.nextInt();
        }

        binarySearch access = new binarySearch();
        System.out.println("The sorted numbers are: ");
        access.sort(x);
        System.out.println();
        
        System.out.print("Enter the number you want to search: ");
        int value = input.nextInt();

        System.out.print("The search number is on the index ");
        System.out.print(access.binSearch(x, 0, x.length-1, value));
    }

}
READ MORE - Binary Search Using Recursion in java

Recursive Linear Search in java


public class Linear_Search

{

public void linSearch2(int[] arr, int fIndex, int lIndex, int searchNum)

{

if(fIndex == lIndex)

{

System.out.print("-1");

}

else

{

if(arr[fIndex] == searchNum)

{

System.out.print(fIndex);

}

else

{

linSearch2(arr, fIndex+1, lIndex, searchNum);

}

}

}

//main class


import java.util.Scanner;

public class Main {


    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);

        System.out.print("Enter the size of the array: ");
        int size = input.nextInt();
        System.out.print("Enter an array of numbers: ");

        int[] arr = new int[size];

        for(int i=0; i<arr.length; i++)
        {
            arr[i]=input.nextInt();
        }

        System.out.print("Enter the number you want to search: ");
        int search = input.nextInt();

       

        Linear_Search access = new Linear_Search();

        System.out.print("The position of the search item is at array index ");
        access.linSearch2(arr, 0, arr.length, search);
    }

}

READ MORE - Recursive Linear Search in java

How to sort numbers in Bubble Sort


public class BubbleSort
{

 public void bubbleSort(int[] arr){
     for(int i=0; i<arr.length; i++){
        for(int j=1; j<arr.length; j++){
            if(arr[j]< arr[j-1] ){
                int temp = arr[j];
                arr[j] = arr[j-1];
                arr[j-1] = temp;            
            }
        }
     }

     for(int i=0; i<arr.length; i++)
     {
         System.out.print(arr[i] + " ");
     }
}

}

//main class

import java.util.Scanner;

public class Main
{

   
    public static void main(String[] args)
    {

        Scanner input = new Scanner(System.in);

        System.out.print("Enter the size of the array: ");
        int n = input.nextInt();
        int[] x = new int[n];

        System.out.print("Enter "+ n +" numbers: ");
        for(int i=0; i<n; i++)
        {
            x[i] = input.nextInt();
        }
        
        BubbleSort access = new  BubbleSort();
 System.out.print("The Sorted numbers: ");
        access.bubbleSort(x);
    }

}
READ MORE - How to sort numbers in Bubble Sort

Reverse string Or Print String Backward using Recursion


public class StringBackward
{
    public static void reverseString(String word, int size)
    {
       if(size==0)
       {
           return;
       }
       else
       {
          System.out.print(word.charAt(size-1));
          reverseString(word, size-1);
       }
    }

}

//main class

import java.util.Scanner;

public class Main {

    public static void main(String[] args)
    {
      Scanner input = new Scanner(System.in);

       String word;
       System.out.print("Enter a word: ");
       word = input.next();

        StringBackward access = new  StringBackward();
        System.out.print("The reverse word is: ");
        access.reverseString(word, word.length());
        System.out.println();

    }

}
READ MORE - Reverse string Or Print String Backward using Recursion

How to Sort Numbers using Selection Sort


public class SelectionSort
{

     public void SelectionSort(int[] arr){
     for(int i=0; i<arr.length; i++)
     {
        for(int j=i+1; j<arr.length; j++)
        {
            if(arr[i] > arr[j] )
            {
                int temp = arr[j];
                arr[j] = arr[i];
                arr[i] = temp;
            }
        }
     }

     for(int i=0; i<arr.length; i++)
     {
         System.out.print(arr[i] + " ");
     }
}

//main class


import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {

        Scanner input = new Scanner(System.in);

        System.out.print("Enter the size of the array: ");
        int n = input.nextInt();
        int[] x = new int[n];

        System.out.print("Enter "+ n +" numbers: ");
        for(int i=0; i<n; i++)
        {
            x[i] = input.nextInt();
        }

        SelectionSort access = new  SelectionSort();
        System.out.print("The Sorted numbers: ");
        access.SelectionSort(x);
    }

}
READ MORE - How to Sort Numbers using Selection Sort

Add Numbers inside an Array Using Recursion


public class Array
{
    public static int array( int[] arr, int first, int last)
    {
      //  int sum = 0;
        if(arr[first] == arr[last])/* must be if(first == last),but try this one too, study the code, it is interesting */
        {
           return arr[first];
        }
        else
        {  
           return arr[first] + array(arr, first+1, last);
             
        }
       
    }
   

}

//main class


import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the size of the input you want to enter: ");
        int size = input.nextInt();
        int[] numArr = new int[size];

        System.out.print("Enter "+ size +" numbers: ");
        for(int i=0; i<numArr.length; i++)
        {
          numArr[i]=input.nextInt();
        }

        System.out.print("The sum of the numbers is: "+   Array.array(numArr, 0 , size-1) );
            

    }
}
READ MORE - Add Numbers inside an Array Using Recursion

Add Numbers inside an Array using For Loop


import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the size of the input you want to enter: ");
        int size = input.nextInt();
        int[] numArr = new int[size];
        int sum=0;
        
 System.out.print("Enter "+ size +" numbers: ");
        
 for(int i=0; i<numArr.length; i++)
        {
          numArr[i]=input.nextInt();
          sum = sum + numArr[i];
        }
    
        System.out.print("The sum of the numbers is: " + sum);
    }
}
Sample Output:
Enter the size of the input you want to enter: 5
Enter 5 numbers: 34 2 5 3 6
The sum of the numbers is: 50
If you want to make a method and segregate the implementation of sum for the sake of practice in Object Oriented Programming, just simply code it this way.
//java class

public class ArraySum
{
    public int sumOfArray(int[] array)
    {
        int sum = 0;
        for(int i=0; i<array.length; i++)
        {
            sum = sum + array[i];
        }

        return sum;
    }
}

//main class


import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the size of the input you want to enter: ");
        int size = input.nextInt();
        int[] numArr = new int[size];
        
        System.out.print("Enter "+ size +" numbers: ");
        for(int i=0; i<numArr.length; i++)
        {
          numArr[i]=input.nextInt();
         
        }

        ArraySum access = new ArraySum();
        System.out.print("The sum of the numbers is:" + access.sumOfArray(numArr));        

    }
}
READ MORE - Add Numbers inside an Array using For Loop

Print Different Asterisk Shapes in java


//main method
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = input.nextInt();
Asterisk1 access = new Asterisk1();
access.asterisk2(n);
}
}
//java class
public class Asterisk1 {
private int count = 0;
public void asterisk1(int n) {
if(n==0) {
System.out.println();
}
else {
System.out.print("*");
asterisk1(n-1); } }
public void asterisk2( int n) {
if(n==0){
return; }
else {
asterisk1(n);
asterisk2(n-1);
}
}
}
This program will output the asterisk in this form. If the number 4 is entered the form will be like this.
****
***
**
*
2. A Java source code for another Asterisk Form
/*The following code will have the same method as the first but different in implementation*/ //main method
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = input.nextInt();
Asterisk1 access = new Asterisk1();
access.asterisk2(n,1);
}
}
// java class
public class Asterisk1 {
private int count = 0;
public void asterisk1(int n) {
if(n==0) {
System.out.println();
}
else {
System.out.print("*");
asterisk1(n-1);
}
}
public void asterisk3(int count,int m) {
if( count == 0) {
System.out.println();
} else {
asterisk1(m);
asterisk3(n-1,m+1);
}
}
}
The output of this code if number 4 is entered will be like this.
*
**
***
****

To get a form that would look like this,
****
***
**
*
*
**
***
****
3. Here is the other code.

//main method
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = input.nextInt();
Asterisk1 access = new Asterisk1();
access.asterisk2(n); access.asterisk3(n,1);
}
}
// java class
public class Asterisk1 {
private int count = 0;
public void asterisk1(int n) {
if(n==0) { System.out.println();
} else {
System.out.print("*");
asterisk1(n-1);
}
}
public void asterisk2( int n) {
if(n==0) {
return;
} else {
asterisk1(n);
asterisk2(n-1);
}
}
public void asterisk3( int n,int m)
{ if( n == 0) {
System.out.println();
} else {
asterisk1(m);
asterisk3(n-1,m+1);
}
}
}
4. Lastly, to acquire a shape like this,
*
**
***
****
****
***
**
*
here is the code:
//main method
package prog_proj2;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = input.nextInt();
Asterisk1 access = new Asterisk1();
access.asterisk3(n); access.asterisk2(n);
}
}
//java class
public class Asterisk1 {
private int count = 0;
public static void asterisk1(int n) {
if(n==0) { System.out.println();
} else {
System.out.print("*");
asterisk1(n-1);
}
}
public void asterisk2( int n) {
if(n==0) { return;
} else {
asterisk1(n);
asterisk2(n-1);
}
}
public void asterisk3( int n) {
count++;
if( n == 0) {
return;
} else {
asterisk1(count);
asterisk3(n-1);
}
}
}
READ MORE - Print Different Asterisk Shapes in java

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|