- public class NumberFactorial {
- public static void main(String[] args) {
- int number = 5;
- int factorial = number;
- for(int i =(number - 1); i > 1; i--)
- {
- factorial = factorial * i;
- }
- System.out.println("Factorial of a number is " + factorial);
- }
- }
Friday, 24 February 2012
Factorial
Saturday, 18 February 2012
Swapping
- public class SwapDemo {
- public static void main(String[] args) {
- int num1 = 10;
- int num2 = 20;
- System.out.println("Before Swapping");
- System.out.println("Value of num1 is :" + num1);
- System.out.println("Value of num2 is :" +num2);
- //swap the value
- swap(num1, num2);
- }
- private static void swap(int num1, int num2) {
- int temp = num1;
- num1 = num2;
- num2 = temp;
- System.out.println("After Swapping");
- System.out.println("Value of num1 is :" + num1);
- System.out.println("Value of num2 is :" +num2);
- }
- }
Tuesday, 14 February 2012
Hello World
- public class HelloWorldExample {
- public static void main(String args[]) {
- System.out.println("Hello World !");
- }
- }
Subscribe to:
Posts (Atom)