[Go to site: main page, start]

0% found this document useful (0 votes)
2 views2 pages

Methods in Java Program

The Java program defines a class 'calci' that performs various arithmetic operations and checks on three integers input by the user. It includes methods for addition, subtraction, finding the greater value among three numbers, calculating factorial, swapping two numbers, and checking if a number is prime. The main method orchestrates these operations and displays the results to the user.

Uploaded by

tanyafds
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Methods in Java Program

The Java program defines a class 'calci' that performs various arithmetic operations and checks on three integers input by the user. It includes methods for addition, subtraction, finding the greater value among three numbers, calculating factorial, swapping two numbers, and checking if a number is prime. The main method orchestrates these operations and displays the results to the user.

Uploaded by

tanyafds
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

package javaProgramming;

import [Link];

public class calci


{
public static void main(String args[])
{
Scanner sc= new Scanner([Link]);
[Link]("a = ");
int a = [Link]();
[Link]("b = ");
int b= [Link]();
[Link]("c = ");
int c=[Link]();
calci ob = new calci();
[Link]("1. Addition of a and b = " +[Link](a, b));
substraction(a, b);
greatervalue(a, b, c);
[Link]("4. Factorial of " +c+ " = " +[Link](c));
//[Link](c);
[Link](a, b);
[Link](c);
}
int result;
static int minus;
public int addition(int x, int y)// instance return type method
{
result = x+y;
return result;
}
public static void substraction(int x, int y) // no return type static method
{
minus= x-y;
[Link]("2. Substraction of a and b = " +minus);
}
public static void greatervalue(int x, int y, int z)//no return type no static
{
if(x>y & x>z)
{
[Link]("3." +x+ " is a greater number among a, b and c");
}
if(y>x & y>z)
{
[Link]("3." +y+ " is a greater number among a, b and c");
}
else
{
[Link]("3." +z+ " is agreater number among a b and c. ");

}
}
public int factorial(int x)
{
int fact=1;
for(int i=x;i>=1;i--)
{
fact=fact*i;

//[Link]("factorial of " +x+ "is:" +fact );


}
return fact;
}

public void swapping(int x, int y)//no return type no static


{
int z;
z=x;
x=y;
y=z;
[Link]("5. After swapping: b = " +y+ " & a = " +x);

}
public void checkprime(int x) // method for check a number is prime or not.
{
int n=x/2, flag=0;
for(int i=2;i<=n;i++)
{
if(x%i==0)
{
[Link]("6. " +x+" is not a prime number");
flag=1;
break;
}}
if(flag==0)
{
[Link]("6. " +x+ " is a prime number");
}
}

You might also like