A simple program that I wrote using Java Programming language and Spring Framework to get a number from the user and then compute for the factorial number value.
My mobile number here in the Philippines is 09173084360
Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
My mobile number here in the Philippines is 09173084360
Sample Program Output
Program Listing
TestSpringProject.java
package org.gontuseries.springcore;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestSpringProject {
public static void main(String[] args) {
@SuppressWarnings("resource")
ApplicationContext context =
new ClassPathXmlApplicationContext("SpringConfig.xml");
Factorial FactorialObj = (Factorial) context.getBean("Factorial_Bean");
FactorialObj.solve();
}
}
Factorial.java
package org.gontuseries.springcore;
import java.util.Scanner;
public class Factorial {
int number=0, counter=0, fact_number = 1;
public void solve() {
@SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
System.out.println();
System.out.println("Factorial Number in Java Spring Framework");
System.out.println("\n");
System.out.print("Give a Number : ");
number = in.nextInt();
if ( number < 0 )
System.out.println("The give number should be positive.");
else
{
for ( counter = 1 ; counter <= number ; counter++ )
fact_number = fact_number *counter;
System.out.println("\n");
System.out.println("Factorial of "+ number +" is equal to "+fact_number+".");
}
System.out.println("\n");
System.out.println("End of Program");
}
}
SpringConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="Factorial_Bean" class="org.gontuseries.springcore.Factorial">
</bean>
</beans>
Thank you for sharing this blog. This blog will help to improve my knowledge.
ReplyDeleteSpring Training in Chennai | Spring framework Training | Spring framework Certification | Spring Hibernate Training in Chennai