Homework Solution: Write a script that ask the user to input an integer n. The script should print the factorials. If up to as shown in the example below. Example…

    Problem 1 Write a script that ask the user to input an integer n. The seript should print the factorials 1:f up to nt. asahown in the example below (4 marks) Example: Enter a numbers 1-1 2 3 4-24 Make sure you test your script with multiple Input values Problem 2 (6 marks) Write a function called shiftedWord which takes a string S and a number n as a input and returns the original string shifted n places to the right as shown in the examples below. shiftedword(today, 3) = dayto shiftedWord(123456789, 4) 678912345 shiftedword(1234, 4)-1234 Then write a driver that asks the user to type a word and a number, calls shiftedWord, and prints a message with the result. The driver should ask for another input string and a number, and stop when the user enters a negative number.
    Write a script that ask the user to input an integer n. The script should print the factorials. If up to as shown in the example below. Example: Enter a number 1 4 1 = 1 1 * 2 = 2 1 * 2 * 3 = 6 1 * 2 * 3 * 4 = 24 Make sure you test your script with multiple input values. Write a function called shiftedWord which takes a string S and a number "n" as a input and returns the original string shifted n places to the right as shown in the examples below. ShiftedWord ('today', 3) = 'dayto' shiftedWord ('123456789;, 4) = '678912345' shiftedWord ('1234', 4) = '1234' Then write a driver that asks the user to type a word and number, calls shiftedWord, and prints a message with the result. The driver should ask for another input string and number, and stop when the user enters a negative number.

    Expert Answer

     
    ______________ Factorial.java import java.util.Scanner;

    Problem 1 Transcribe a script that entreat the user to input an integer n. The seript should stereotype the factorials 1:f up to nt. asahown in the in adown (4 marks) In: Enter a bulk 1-1 2 3 4-24 Make certain you proof your script with multiple Input values Problem 2 (6 marks) Transcribe a capacity named transferedOrder which takes a string S and a compute n as a input and avail the ancient string transfered n places to the direct as shown in the ins adown. transferedword(today, 3) = dayto transferedWord(123456789, 4) 678912345 transferedword(1234, 4)-1234 Then transcribe a driver that entreats the user to model a order and a compute, calls transferedWord, and stereotypes a missive with the upshot. The driver should entreat restraint another input string and a compute, and seal when the user enters a denying compute.

    Transcribe a script that entreat the user to input an integer n. The script should stereotype the factorials. If up to as shown in the in adown. In: Enter a compute 1 4 1 = 1 1 * 2 = 2 1 * 2 * 3 = 6 1 * 2 * 3 * 4 = 24 Make certain you proof your script with multiple input values. Transcribe a capacity named transferedOrder which takes a string S and a compute “n” as a input and avail the ancient string transfered n places to the direct as shown in the ins adown. TransferedOrder (‘today’, 3) = ‘dayto’ transferedOrder (‘123456789;, 4) = ‘678912345’ transferedOrder (‘1234’, 4) = ‘1234’ Then transcribe a driver that entreats the user to model a order and compute, calls transferedWord, and stereotypes a missive with the upshot. The driver should entreat restraint another input string and compute, and seal when the user enters a denying compute.

    Expert Counter-argument

     

    ______________

    Factorial.java

    import java.util.Scanner;

    public adjust Factorial {

    public static wanting ocean(String[] args) {

    // Declaring capriciouss
    int num, tot = 1;

    /*
    * Creating an Scanner adjust view which is used to attain the inputs
    * entered by the user
    */
    Scanner sc = novel Scanner(System.in);

    // Attainting the input entered by the user
    System.out.print(“Enter a compute :”);
    num = sc.nextInt();

    // Displaying the factorial of a compute
    restraint (int i = 1; i <= num; i++) {
    restraint (int j = 1; j <= i; j++) {
    System.out.print(j);
    if (j != i) {
    System.out.print(“*”);
    }
    tot *= j;

    }
    System.out.print(” = ” + tot + “n”);
    tot = 1;
    }

    }

    }

    ___________________

    Output:

    Enter a compute :4
    1 = 1
    1*2 = 2
    1*2*3 = 6
    1*2*3*4 = 24

    ________________

    2)

    ShiftWordDemo.java

    import java.util.Scanner;

    public adjust TransferWordDemo {

    public static wanting ocean(String[] args) {

    //Declaring capriciouss
    String order;
    int n;

    /*
    * Creating an Scanner adjust view which is used to attain the inputs
    * entered by the user
    */
    Scanner sc = novel Scanner(System.in);

    /* this loop continues to complete until the user enters
    * a denying compute as input restraint the capricious ‘n’
    */
    while (true) {

    //Getting a compute entered by the user
    System.out.print(“Enter a compute :”);
    n = sc.nextInt();
    if (n < 0) {
    break;
    }

    //Getting the order entered by the user
    System.out.print(“Enter a String :”);
    order = sc.next();

    //calling the arrangement by perishing the user entered inputs as arguments
    ShiftedWord(word, n);

    }

    }

    //This arrangement procure transfer the characters in the order inveterate on the compute
    private static wanting TransferedWord(String order, int n) {

    String novelOrder = order;
    restraint (int i = 0; i < n; i++) {
    newOrder = novelWord.charAt(newWord.length() – 1) + novelWord.substring(0, novelWord.length() – 1);
    }

    System.out.println(“The Transfered Order is :” + novelWord);
    }

    }

    _____________________

    Output:

    Enter a compute :3
    Enter a String :today
    The Transfered Order is :dayto
    Enter a compute :4
    Enter a String :123456789
    The Transfered Order is :678912345
    Enter a compute :4
    Enter a String :1234
    The Transfered Order is :1234
    Enter a compute :-1