Professional Documents
Culture Documents
Assignment 1 .: Write A Number To Calculate Factorial of A Number
Assignment 1 .: Write A Number To Calculate Factorial of A Number
int n, c, f = 1;
//Show a message to a user to input a number
System.out.println("Enter an integer to calculate its
factorial");
Scanner in = new Scanner(System.in);
Output :-
b.Write a number that accepts an integer as input and prints the table of that
integer up to 12. For e.g. is the user enters 7
import java.util.Scanner;
public class Assignment1a {
// Driver code
public static void main(String[] args)
{
int j,n;
System.out.println ("\n");
Output :
c.Write a program that reads in a number form the user and then displays
the Hailstone sequence for the number.
import java.util.*;
public class Assignment1a {
static int c;
if (N == 1 && c == 0) {
// N is initially 1.
return c;
}
else if (N == 1 && c != 0) {
// N is reduced to 1.
c++;
return c;
}
else if (N % 2 == 0) {
// If N is Even.
c++;
HailstoneNumbers(N / 2);
}
else if (N % 2 != 0) {
// N is Odd.
c++;
HailstoneNumbers(3 * N + 1);
}
return c;
}
// Driver code
public static void main(String[] args)
{
int N = 6;
int x;