Help with very difficult program please!!!

If anyone could please give me the code for these 4 programs (2 questions) it would be very much appreciated!!

1.Write a program that reads an integer value n from the keyboard and calculates n!. The equation is as follows:

n!=n x (n - 1) x (n - 2) x (n - 3) x ..... x (n - n + 1)

For example, if the value of n is 4, then the calculation process is

4!= 4 x (4 - 1) x (4 - 2) x (4 - 3) = 4x3x2x1=24

The program will

?prompt an input message to users and accept an integer value n

?carry out calculations using the equation above

?print the result on the screen [Hint: using a 揻or?loop structure]

2.The formula: 1 inch = 2.54 centimetres can be used to perform conversions between inches and centimetres. Given five numbers of inches, i.e. 1.1, 2.3, 3, 4.2, 4.8, you are require to write three programs that convert each of these numbers of inches to centimetres.

a)Program 1 will

?initialize an array with the given numbers of inches (1.1, 2.3, 3, 4.2, 4.8)

?perform the conversion of each of them

?print the centimetres on the screen

b)Program 2 will

?Input the five numbers of inches to an array from the keyboard (using the uuInOut class)

?perform the conversion of each number of the inches

?print the centimetres on the screen

c)Modify Program 2 to Program 3 which contains of three methods embedded in your program

?Method 1 is used for inputting the five numbers of inches from the keyboard (you must use a 搗oid method without parameters?

?Method 2 is used to do conversions between inches and centimetres (you must use a 搗alue method without parameters?

?Method 3 is a 搈ain?which calls method 1 and 2, and prints the results on the screen

[1807 byte] By [1utda] at [2007-11-26 22:26:13]
# 1
> n!=n x (n - 1) x (n - 2) x (n - 3) x ..... x (n - n + 1)Yeah, (n - n + 1) is really cool! :)Thanks for learning us about factorials. This definition rocks!
Michael.Nazarov@sun.coma at 2007-7-10 11:27:33 > top of Java-index,Java Essentials,New To Java...
# 2

> n!=n x (n - 1) x (n - 2) x (n - 3) x ..... x (n - n + 1)

> For example, if the value of n is 4, then the calculation process is

> 4!= 4 x (4 - 1) x (4 - 2) x (4 - 3) = 4x3x2x1=24

This example is incorrect... You should wrote:

4!= 4 x (4 - 1) x (4 - 2) x ( 4 - 3 ) x ..... x (4 - 4 + 1) = 4x3x2x1x.....x1=24

It's very difficult to code ..... function :(

Michael.Nazarov@sun.coma at 2007-7-10 11:27:33 > top of Java-index,Java Essentials,New To Java...
# 3
yeah sorry mate, typing error there, can you help?
1utda at 2007-7-10 11:27:33 > top of Java-index,Java Essentials,New To Java...
# 4

import java.util.Scanner;

class FactorialCalc

{

public int factorial( int N )

{

if ( N == 0 )

return 1;

else

return N * factorial( N-1 ) ;

}

}

class FactorialTester

{

public static void main ( String[] args)

{

Scanner s = new Scanner(System.in);

int number;

FactorialCalc f = new FactorialCalc();

System.out.print("Enter a number: ");

number = s.nextInt();

int result = f.factorial(number);

System.out.println("Factorial(" + number + ") is " + result );

}

}

i am at work. i will post the answer later on for 2nd question.

fastmikea at 2007-7-10 11:27:33 > top of Java-index,Java Essentials,New To Java...
# 5

Don't know if someone has already posted it.

import java.util.Scanner;

public class Factorial {

public static void main (String[] args) {

Scanner scan=new Scanner (System.in);

System.out.println("Enter input for n:");

int n = scan.nextInt();

System.out.println(n + "! = " + factorial(n));

}

private static int factorial(int n) {

if (n == 0) return n;

else return n * factorial(n - 1);

}

}

TimSparqa at 2007-7-10 11:27:33 > top of Java-index,Java Essentials,New To Java...