Sunday, February 9, 2020

Kerala State Rutronix , Pratical Examination -july 2018 java Answer




Factors given number program in Java  Program 

Example :- Image result for factors of number 15 concept? 

Image result for factors of 15 number? 

1. Factors of number

import java.util.Scanner;
class factors
{
public static void main(String []args)
{
int Number, i;
Scanner sc = new Scanner(System.in);
System.out.println("Please Enter any number to Find Factors: ");
Number = sc.nextInt();
    for(i = 1; i <= Number; i++)
    {
    if(Number%i == 0)
    {
    System.out.format(" %d  ", i);
    }
    }
}
}

 

 

 2. Factorial of number

 

Image result for factorial of  5 number? 

 import java.util.Scanner;
class factory
{
public static void main(String []args)
{
int n,f=1,a;
Scanner  obj=new Scanner(System.in);
System.out.println("  Enter a number :"  );
n=obj.nextInt();
for(a=1;a<=n;a++)
{
System.out.println( a);
System.out.println("  "  );
f=f*a;
a++;
}
System.out.println("   Factorial is  :"   +f);
}
}

 

No comments:

Post a Comment