Java Coding for Factorial in Non-Static Method

Hey Hi Guys Now we are adding new Content in our related to java coding. in this post our topic is Java Coding For Factorial in Non-Static Method.

I hope you also interested for java coding so we will tell you about full information related to our java program so today i will discuses about java coding for factorial by using non static method.

So if we want coding for Factorial by using Non Static method. there is some steps you need to do ass per following-

Factorial Using Non-Static Method Steps-

  • First we need to create one class inside the package
  • our class name is it should any thing but it start from Capital Latters.
package logicaltask;
import java.util.Scanner;
public class FactorialWhile {
  • if we Are declaring one class after we need some instance variable.
  • Variable Its Should be any thing
  • For Example, This Are variables.
	int start,end,up,down,nes;
  • After Declaring Instance Variable we need to Declare some Constructor.
  • Constructor is nothing but our class name. Bothe are same.
  • For Example I will Declare Here One Constructor.
//Declaring Constructor
	public FactorialWhile () {
		start= 1;
		end= 7;
		up=1;
	}
  • after Declaring one Constructor then i will go for Non static method.
  • now i am going to declaring one non static method
  • as we know non Static method. non static method we can Declare inside the Class.
  • Standard Syntax for non static method is- public void Method_Name () {}
  • There is small Example For Non Static method.
//Initialization Non Static Method
	public void is (int end) {
		//While Loop Declaration
		while (start<=end) {
			nes= start++;
			up = up*nes;
		}
		System.out.println("Factorial of " + end + " is " + up);
	}
  • in this non static method i will declaring while loop in
  • while loop as we know if our iteration is not fix then we are using while loop.
  • but here is iteration is fix here can we also use While loop ok.
  • in that i am using one condition as start <= end, it means this while loop continuous iteration are running.
  • if my value is more than then my while loop getting terminated.
//Usage Main Method
	public static void main (String [] args) {
		//Creating Object For Scanner Class
		Scanner kee = new Scanner(System.in);
		System.out.println("give The Number For Factorial ");
		int end = kee.nextInt();
		kee.close();
		// Creating Object for Calling Non Static Method
		FactorialWhile mobile = new FactorialWhile();
		mobile.is(end);
	}
  • after Non static method then we need to declaring main method as we know standard syntax of Main Method.
public static void main (String [] args ) {

}
  • then we need to created one main method in main method.
  • in after creating main method i will Creating one Object For Scanner Class.
  • after Scanner object we also required to Create One Variable.
  • then We need to close Object Also.
//Usage Main Method
	public static void main (String [] args) {
		//Creating Object For Scanner Class
		Scanner kee = new Scanner(System.in);
		System.out.println("give The Number For Factorial ");
		int end = kee.nextInt();
		kee.close();
  • then we need create another object for calling non static method.
  • and then we simply calling non static method.
//Usage Main Method
public static void main (String [] args) {
    //Creating Object For Scanner Class
    Scanner kee = new Scanner(System.in);
    System.out.println("give The Number For Factorial ");
    int end = kee.nextInt();
    kee.close();
    // Creating Object for Calling Non Static Method
    FactorialWhile mobile = new FactorialWhile();
    mobile.is(end);
}

Java Coding For Factorial in Non-Static Method

Here full source code of Java Coding For Factorial in Non-Static Method. just copy and run it.

package logicaltask;
import java.util.Scanner;
public class FactorialWhile {
	//Declaring Instance Variable 
	int start,end,up,down,nes;
	//Declaring Constructor
	public FactorialWhile () {
		start= 1;
		end= 7;
		up=1;
	}
	//Initialization Non Static Method
	public void is (int end) {
		//While Loop Declaration
		while (start<=end) {
			nes= start++;//1,2,3,4,5,6,7
			up = up*nes;
		}
		System.out.println("Factorial of " + end + " is " + up);
	}
	//Usage Main Method
	public static void main (String [] args) {
		//Creating Object For Scanner Class
		Scanner kee = new Scanner(System.in);
		System.out.println("give The Number For Factorial ");
		int end = kee.nextInt();
		kee.close();
		// Creating Object for Calling Non Static Method
		FactorialWhile mobile = new FactorialWhile();
		mobile.is(end);
	}
}

There is code of Factorial Using Non-Static Method. here full source code. just copy and do your work.

Leave a Reply

Your email address will not be published.

Sanjay Raut: संजय राउत के घर रविवार सुबह पहुंची ED, President Draupadi Murmu Vedanta declares dividend of Rs 19.5 per share CBSE 10th 12th Results 2022-जारी होने वाला है which laptop is best for gaming