0% found this document useful (0 votes)
3 views4 pages

Interface

The document contains a Java program that implements multiple interfaces for calculating the factorial, sum of digits, reverse of digits, and printing a triangle pattern. The main class 'all' implements four interfaces and provides methods to perform these calculations based on user input. The program demonstrates its functionality by prompting the user for input and displaying the results for each operation.

Uploaded by

piyushnagar128
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)
3 views4 pages

Interface

The document contains a Java program that implements multiple interfaces for calculating the factorial, sum of digits, reverse of digits, and printing a triangle pattern. The main class 'all' implements four interfaces and provides methods to perform these calculations based on user input. The program demonstrates its functionality by prompting the user for input and displaying the results for each operation.

Uploaded by

piyushnagar128
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
You are on page 1/ 4

import java.util.

Scanner;

interface In1
{
public void fact();
public void show1();
}
interface In2
{
public void sum_digit();
public void show2();
}
interface In3
{
public void rev_digit();
public void show3();
}
interface In4
{
public void trangle();
}

class all implements In1, In2, In3, In4


{
int fact=1, n, i, m,sum=0,rev=0,j;
public void fact()
{
System.out.print("Enter the number whose find the
factorial=\t");
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
for(i=n;i>=1;i--)
{
fact=fact*i;
}
}
public void show1()
{
System.out.println("\n Factorial ="+fact);
}

public void sum_digit()


{
System.out.print("Enter the number whose find the Sum of
Digit=\t");
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
while (n>0)
{
m=n%10;
sum=sum+m;
n=n/10;
}
}
public void show2()
{
System.out.println("\n Sum of Digit ="+sum);
}

public void rev_digit()


{
System.out.print("Enter the number whose find the
Reverse of Digit=\t");
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
while (n>0)
{
m=n%10;
rev=rev*10+m;
n=n/10;
}
}
public void show3()
{
System.out.println("\n Reverse of Digit ="+rev);
}
public void trangle()
{
System.out.print("Find the How Many Row=\t");
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();

}
}
class Inter
{
public static void main(String[] args)
{
all a=new all();
a.fact();
a.show1();
a.sum_digit();
a.show2();
a.rev_digit();
a.show3();
a.trangle();

}
}

Output
Enter the number whose find the factorial= 5

Factorial =120
Enter the number whose find the Sum of Digit= 12

Sum of Digit =3
Enter the number whose find the Reverse of Digit= 321

Reverse of Digit =123


Find the How Many Row= 6
*
**
***
****
*****
******

You might also like