Monday, December 22, 2014

Factorial number by recursion Operator Precedence and Associativity program in java



Program of factorial number by recursion

class factrecursion
{  
static int fact(int n)
{  
if(n==1)  
return 1;  
return n*=fact(n-1);  
}  
public static void main(String args[])
{  
int f=fact(5);  
System.out.println(f);  
}  
}  

Operator Precedence

class operatorprecedence
{
public static void main(String args[])
{
int i = 40;
int j = 80;
int k = 40;
int l = i + j / k;
System.out.println("value of L :" + l);
int m = (i + j) / k;
System.out.println("Value of M:" + m);
}
}

Operator Associativity

package jbt.bean;
public class OperatorAssociativityExample
{
public static void main(String args[])
{
int i = 40;
int j = 80;
int k = 40;
int l = i / k * 2 + j;
System.out.println("value of L :" + l);
int m = i / (k * 2) + j;
System.out.println("Value of M:" + m);
}
}

No comments:

Post a Comment