/*The Given Program Calculates the Following Mathematical operations:
*1. Square root
*2. POwer of a number
*3. Sine Value
*4. Cosine Value
*5. Logarithm Value
*6. Absolute value
*
*
/* Simple Java Program For Various Mathematical Operation */
import java.lang.Math;
class MathFunctions
{
public static void main(System args[])
{
double x = 7;
double y;
System.out.println("Given Number "+x);
y = Math.sqrt(x);
System.out.println("Square Root : "+y);
y = Math.pow(x,3);
System.out.println("Power : "+y);
y = Math.sin(x);
System.out.println("Sine : "+y);
y = Math.cos(x);
System.out.println("Cosine : "+y);
y = Math.log(x);
System.out.println("Logrithm : "+y);
y = Math.abs(x);
System.out.println("Absolute Value : "+y);
}
}
Given Number 7.0
Square Root : 2.6457513110645907
Power : 343.0
Sine : 0.6569865987187891
Cosine : 0.7539022543433046
Logrithm : 1.9459101490553132
Absolute Value : 7.0
*/
/* Simple Java Program For Claculating Area Of A Rectangle Using two Classes */
class TwoClasses
{
float length, breadth;
void getdata(float a, float b)
{
length = a;
breadth = b;
}
}
class Area
{
public static void main(String args[])
{
float area;
TwoClasses Rectangle = new TwoClasses(); // Object Reactangle
Rectangle.getdata(25,35);
area = Rectangle.length * Rectangle.breadth;
System.out.println("Area : "+area);
}
}
/* Output *
*Area : 875
*/
/************ Implementaion On Numbers In Java*************/
class Numbers
{
public static void main(String args[])
{
int i,great_no,small_no;
int no[] = {5,78,1,6,74,9,6,4,6,7};
System.out.println("Elements in the Array : ");
for(i=0;i< 10;i++)
System.out.print(no[i]+"\t");
great_no = no[0]; small_no = no[0];
for(i=1;i< 10;i++)
{
if(great_no< no[i])
great_no = no[i];
else if(small_no>no[i])
small_no = no[i];
}
System.out.print("\nGreatest Number : "+great_no);
System.out.print("\nSmallest Number : "+small_no);
}
}
/************** OUTPUT ****************
Elements in the Array :
5 78 1 6 74 9 6 4 6 7
Greatest Number : 78
Smallest Number : 1 */
/****** Java Program To Print Sum Of 'n' Number ******/
class Add
{
public static void main (String args[])
{
int n = 15;
int sum = 0;
for(int i = n;i>=0;i--)
sum = sum + i;
System.out.println("Sum = "+ sum);
}
}
/*************** OUTPUT *************
* *
* Sum = 120 */
/********** Java Program To Print Reverse Of A Number ************/
class Reverse
{
public static void main(String args[])
{
int i,s=0,a = 120;
int no[] = new int[10];
System.out.print("Original Number : "+a);
for(i=0;i< 10;i++)
{
if(a!= '\0')
{
no[i] = a%10;
a = a / 10;
s++;
}
else break;
}
System.out.print("\n\nReversed Number : ");
for(i=s;i>0;i--)
{
System.out.print(no[i]);
}
}
}
/************ OUTPUT ************
* Original Number : 120
* Reversed Number : 021 */