1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
STALIN [3.7K]
3 years ago
15

Write a function in Java called factorial() that will take a positive integer as input and returns its factorial as output.

Computers and Technology
1 answer:
serg [7]3 years ago
4 0

Answer:

The function is as follows:

public static int factorial(int n){

       int fact = 1;

       for(int i=2;i<=n;i++){

           fact*=i;

       }

       return fact;

   }

Explanation:

This line defines the function

public static int factorial(int n){

This declares and initializes variable fact to 1    

  int fact = 1;

This iterates from 2 to n

       for(int i=2;i<=n;i++){

This line multiplies all integers from 1 to n

           fact*=i;

       }

This returns the factorial

       return fact;

   }

You might be interested in
You are given a string of n characters s[1 : : : n], which you believe to be a corrupted text document in which all punctuation
alexdok [17]

Answer: provided in the explanation section

Explanation:

Given that:

Assume D(k) =║ true it is [1 : : : k] is valid sequence  words or false otherwise

  • To determine D(n)

now the sub problem s[1 : : : k] is a valid sequence of words IFF s[1 : : : 1] is a valid sequence of words and s[ 1 + 1 : : : k] is valid word.

So, from here we have that D(k) is given by the following recorance relation:

D(k) = ║ false maximum (d[l]∧DICT(s[1 + 1 : : : k]) otherwise

Algorithm:

Valid sentence (s,k)

D [1 : : : k]             ∦ array of boolean variable.

for a ← 1 to m

do ;

d(0) ← false

for b ← 0 to a - j

for b ← 0 to a - j

do;

if D[b] ∧ DICT s([b + 1 : : : a])

d (a) ← True

(b). Algorithm Output

      if D[k] = = True

stack = temp stack           ∦stack is used to print the strings in order

c = k

while C > 0

stack push (s [w(c)] : : : C] // w(p) is the position in s[1 : : : k] of the valid world at // position c

P = W (p) - 1

output stack

= 0 =

cheers i hope this helps !!!

8 0
3 years ago
1)Write the command that moves the file data1 into the directory testdata:
mrs_skeptik [129]
1) mv data1 testdata/
2) mv data1 ../
3) ls letters

These are the *nix commands. You can find out more by looking at their man pages. You can get more info about the man subsystem by running: man man
8 0
2 years ago
Who was one of the founders of the location sharing site Foursquare​
Shalnov [3]

One of the founders of Foursquare is Dennis Crowley. The other is Naveen Selvadurai. I know you didn't ask for both but I wanted to give them to you just in case. I hope this helps! (:

7 0
3 years ago
Which of the following examines the organizational resource of information and regulates its definitions, uses, value, and distr
hichkok12 [17]

Answer:C)Information management

Explanation: Information management is the technique through which the organization and handling of the the data/ information takes place.This technique is made for helping the organization and their business for the supporting the function and processes.

The facilities provided by the information management system is  development, management, designing, innovation etc.

Other options are incorrect because they are used for the coding process,technology and governing of the data, hence no management activity is done by them.Thus, the correct option is option(C).

4 0
3 years ago
Explain why the computer is powerful working tool???​
notsponge [240]

Answer:

here ya go

Explanation:

A computer is a powerful tool because it is able to perform the information processing cycle operations (input, process, output, and storage) with amazing speed, reliability, and accuracy; store huge amounts of data and information; and communicate with other computers.

8 0
2 years ago
Other questions:
  • Consider that a large online company that provides a widely used search engine, social network, and/or news service is consideri
    12·1 answer
  • Controlled intersections use some form of which of the following:
    7·1 answer
  • Suppose x and y are int variables and ch is a char variable. Consider the following input: 5 28 36 What value (if any) is assign
    11·1 answer
  • How does a author develop a character in a story?
    14·2 answers
  • What techniques overcome resistance and improve the credibility of a product? Check all that apply.
    8·1 answer
  • Examples of analog computer
    8·1 answer
  • In addition to explaining the paper’s topic, a thesis statement provides instructions on how to read the paper. explains why the
    10·2 answers
  • The information given to you by your teachers is always accurate and should never be questioned. Please select the best answer f
    8·1 answer
  • What do you suggest for Father's Day?​
    7·1 answer
  • Select the correct answer.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!