Question

In: Computer Science

Please submit 1) the source code (.java file), and 2) the screenshot of running results of...

Please submit
1) the source code (.java file), and
2) the screenshot of running results of each question.

  1. (Factorials) Write an application that calculates the factorial of 20, and display the results. Note: 1) The factorial of a positive integer n (written n!) is equal to the product of the positive integers from 1 to n. 2) Use type long.

  2. (Largest and Smallest Integers) Write an application that reads five integers and determines and prints the largest and smallest integers in the group. Use for loop.

Solutions

Expert Solution

//import for Scanner
import java.util.Scanner;

//main class
class Main {
  //main method 
  public static void main(String arg[])
  {
    //declaration of number 
    long n,fact=1;
    
    //create scanner object
    Scanner sc = new Scanner(System.in);
    
    //take input from user
    System.out.println("Enter number :");
          n = sc.nextLong();
 
    //calculate factorial from number
          for(int i=1;i<=n;i++)
          {
      fact=fact*i;
    }
    
    //print factorial on console
    System.out.println("factorial = "+fact);
        }
}

output of above code

Largest and Smallest Integers



//import for Scanner
import java.util.Scanner;

//main class
class Main {
  //main method 
  public static void main(String arg[])
  {
    // declaring and creating array objects
    int[] arr = new int[5];
    int min=0, max=0, i=0;
    
    //create scanner object
    Scanner sc = new Scanner(System.in);
    //take input from user
    System.out.println("Enter five numbers :");
    for(i=0; i<arr.length; i++)
    {
      // read input
      arr[i] = sc.nextInt();
    }
          
    max=arr[0];
    min=arr[0];
    for(i =0; i<arr.length ; i++)
    if(arr[i]>max)
    {
      max=arr[i];
    }
    else if(arr[i]<min)
    {
      min=arr[i];
    }

   //print factorial on console
    System.out.println(" smallest integers = "+min);
    System.out.println(" largest integers = "+max);
        }
}

output:


Related Solutions

Directly copy the source code and paste into the Word file. Screenshot of running result must...
Directly copy the source code and paste into the Word file. Screenshot of running result must be presented. 1. (20 points) Write the “Hello, world!” program. 2. (30 points) Write a program to calculate the sum from -5 to10. Use the for loop to do the calculation. 3. (20 points) Write a complete C++ program that asks the user to enter the necessary information about the cylinder, calculate the volume in a function (named as calculate_vol, using reference to pass...
Your hardcopy submission will consist of these two things: Source code (your java file). Screenshot of...
Your hardcopy submission will consist of these two things: Source code (your java file). Screenshot of Eclipse showing output of program. (JPG or PNG format only) Write a program to play the game of Stud Black Jack. This is like regular Black Jack except each player gets 2 cards only and cannot draw additional cards. Create an array of 52 integers. Initialize the array with the values 0-51 (each value representing a card in a deck of cards) in your...
Provide a screenshot of your script code and a screenshot of running the scripts with test...
Provide a screenshot of your script code and a screenshot of running the scripts with test inputs. Write a script to check command arguments (3 arguments maximum). Display the argument one by one. If there is no argument provided, remind users about the mistake.  
Can you provide source code in Java that 1. accepts a two-way acceptor via file; 2....
Can you provide source code in Java that 1. accepts a two-way acceptor via file; 2. and validate if the input string is part of the language
Please submit a screenshot of where your code got compiled, executed, showing the execution result Write...
Please submit a screenshot of where your code got compiled, executed, showing the execution result Write a program/function in python that will perform the following functions, when the program is executed, to demonstrate the features of an OOP language—ADT, inheritance, and polymorphism: Prompt a list of options—the main menu, below to compute the area of selected shape with input parameters: triangle rectangle square circle parallelogram Exit Per the selected option, prompt grader to enter the corresponding required parameters as described...
Write assembler code to print even numbers from 1-20. Submit code and screenshot. I am coding...
Write assembler code to print even numbers from 1-20. Submit code and screenshot. I am coding in NASM on a SASM system.
Java and please have screenshots with source code and output \item[(1)] A palindrome is a string...
Java and please have screenshots with source code and output \item[(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as...
1. Write a Java program and Submit only "one .java file" calledNumbers that calls the...
1. Write a Java program and Submit only "one .java file" called Numbers that calls the following methods and displays the returned value:o Write a method called cubeIt that accepts one integer parameter and returns the value raised to the third power as an integer.2. Write a method called randomInRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive.o Write a method called larger that accepts two double parameters and...
Please show screenshot outputs and fully functional code for the Java program. Write the following methods...
Please show screenshot outputs and fully functional code for the Java program. Write the following methods to   1) read the content of an array of 5 doubles public static double[] readingArray() 2) find and print:the smallest element in an array of 5 double public static void smallest(double [] array) 3) find and print:the largest element in an array of 5 doubles pubic static void largest (double [] array) In the main method - invoke readingArray and enter the following numbers...
Please use C language to code all of the problems below. Please submit a .c file...
Please use C language to code all of the problems below. Please submit a .c file for each of the solutions, that includes the required functions, tests you wrote to check your code and a main function to run the code. Q2. Implement the quick-sort algorithm.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT