ways to create an object in Java Example 2
Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)
3943Program:
// Save it as File name : Factorial.java //ways to create an object in Java example 2 class Factorial{ void fact(int n){ int fact=1; for(int i=1;i<=n;i++){ fact=fact*i; } System.out.println("factorial is := "+fact); } public static void main(String args[]){ Factorial c=new Factorial(); c.fact(5); } }
Output:
factorial is := 120 Press any key to continue . . .
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.