Showing posts with label odd and even numbers using java spring framework. Show all posts
Showing posts with label odd and even numbers using java spring framework. Show all posts

Sunday, May 22, 2016

Odd and Even Numbers Using Java Spring Framework

A simple program that I wrote using Java Programming language and Spring Framework to check if the given number by the user is an Odd and Even Number.

 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");
 
 Odd_Or_Even Odd_Or_EvenObj = (Odd_Or_Even) context.getBean("Odd_Or_Even_Bean");
    
 Odd_Or_EvenObj.checking();
}
}


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="Odd_Or_Even_Bean" class="org.gontuseries.springcore.Odd_Or_Even">
</bean>

</beans>

Odd_Or_Even.java

import java.util.Scanner;

public class Odd_Or_Even {
int number=0;
public void checking() {
 @SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
 System.out.println();
 System.out.println("Odd or Even Number Checker in Java Spring Framework");
 System.out.println("\n");
   
 System.out.print("Give a Number : ");
     number = in.nextInt();
     
     if ( number % 2 == 0 ) {
            System.out.println("\n");
            System.out.println("The number " + number + " is an even number.");
     }
         else {
        System.out.println("\n");
            System.out.println("The number " + number + " is odd number.");
}

 
 System.out.println("\n");
 System.out.println("End of Program");
 
}

}