answer.
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
Blizzard [7]
2 years ago
10

Write a method called fact that recursively calculates the factorial value of its single int parameter. The value returned by fa

ct is a long ..
Computers and Technology
1 answer:
andrey2020 [161]2 years ago
6 0

Answer:

The program to this question can be given as follows:

Program:

//class

public class factorial //defining class

{

//method fact

public static long fact(int x1) //defining method fact

{

//conditional statement

if (x1 <= 1) //if block checks parameter value less then equal to 1

{

return 1; //return value

}

else //else part

{

return (fact(x1 - 1) * (long) x1); //return factors using recursive function

}

}

//method main

public static void main(String[] args) //defining main method

{

long data=fact(5);//defining variable that holds function value

System.out.println("Factorial is: "+data); //print value

}

}

Output:

Factorial is: 120

Explanation:

In the above java program, a class is "factorial" is defined, inside the class, a static method "fact" is declared, that accepts an integer parameter that is "x1" and returns a long value, inside this method a conditional statement is used.

  • If the block it checks parameter value is less then equal to 1, if this condition is true, it will return 1 when this condition is not true. It will go in else part.
  • In else part, it uses a recursive function to calculate factorial of a number and return its value.
  • Then the main method is defined, inside this method a long variable "data" is defined, that call and holds fact function return value, and in the next line, the print function is used to print the data variable value.

You might be interested in
Alice is adding a chart in a spreadsheet. Which option will allow you her to give the chart a suitable title and subtitle?
Anon25 [30]

Chart elements is the answer.


8 0
2 years ago
Read 2 more answers
Mavis is considering signing up for a hosted enterprise software solution for her small business. She recognizes that an advanta
babymother [125]

Since Mavis is considering signing up for a hosted enterprise software solution for her small business, an advantage of the software is <u>lower cost</u>.

A hosted enterprise software solution is typically hosted off-site and in a private server that is owned by a third party. It's vital for organizations as it can be used in managing daily business activities.

The advantages of a hosted software model include reliable backup, reduction in IT costs, scalability of computing resources, etc. It is also necessary for managing critical business processes.

Read related link on:

brainly.com/question/25526416

6 0
1 year ago
Edhesive: Assignment 4: Evens and Odds
solniwko [45]

Answer:

Written in Python

n = int(input("How many numbers do you need to check? "))

odd = 0

even = 0

for i in range(1,n+1):

     num = int(input("Enter Number: "))

     if num%2 == 0:

           print(str(num)+" is an even number")

           even = even + 1

     else:

           print(str(num)+" is an odd number")

           odd = odd + 1  

print("You entered "+str(even)+" even number(s).")

print("You entered "+str(odd)+" odd number(s).")

Explanation:

<em>I've added the full source code as an attachment where I use comments (#) as explanation</em>

Download txt
6 0
2 years ago
Create an application that contains an enumeration that represents the days of the week. Display a list of the days, and then pr
IgorLugansk [536]

Answer:

The program to this question can be defined as below:

Program:

import java.util.*; //import package for user input

enum Days{Sunday, Monday, Tuesday, Wednesday, Thusday, Friday, Saturday} //defining enum

public class DayOfWeek //defining class DayOfWeek

{

  public static void main(String[] args) //defining main method

  {

  System.out.println("Days of the Week: "); //print message  

  for (Days d : Days.values()) //defining for loop to print enums values

  {

  System.out.print(d+"\n");//print values

  }

  System.out.println("Enter your day: "); //print message

  Scanner obx= new Scanner(System.in); //create Scanner class object for user input

  Object d= obx.next(); //create object to hold user-input value

  System.out.print("Business Hours "); //print message

   //check conditions  

  if(Days.Sunday.toString().equals(d)) //defining if block to check if day is Sunday

  {

  System.out.println("from 11 to 5"); //print message

  }

  else if(Days.Saturday.toString().equals(d))// check if the day isn't Sunday

  {

  System.out.println("from 10 to 6");  //print message

  }

  else //else block

  {

      System.out.println("from 9 to 9");//print message

  }

  }

}

Output:

please see the attachment.

Explanation:

In the given code first package is import for user input then the enumeration "Days" is used, in which weekday values are defined. In the next line, the class "DayOfWeek" is defined, in this main method is declared, that first uses a loop to print enum value than it will create object "d" for user input and define conditional statement to check values, that can be described as follows:

  • In the if block it will check if the input value is "Sunday", it will print 11 to 5 business hours, otherwise, it will go to the else if block.
  • In this block it will check, that input value is "Saturday", if it is true it will print 10 to 6 business hours.
  • If both above condition is false so, it will print 9 to 9 business hours.

7 0
2 years ago
In your Works Cited list, you want to cite a book called Freakonomics, by Steven D. Levitt and Stephen J. Dubner. According to M
Zina [86]
Levitt, Steven D., Stephen J. Dubner
4 0
2 years ago
Read 2 more answers
Other questions:
  • Name and summarize the four levels of administration necessary to keep human services organization operating smoothly
    9·2 answers
  • Data Analysis The Iris Plants Database contains 3 classes of 50 instances each, where each class refers to a type of Iris plant.
    15·1 answer
  • Need 2.5 Code Practice Answers
    14·2 answers
  • Write a method called fact that recursively calculates the factorial value of its single int parameter. The value returned by fa
    10·1 answer
  • ________ is a free online service that enables a user to contact a cell phone number to hear who answers the telephone without i
    5·1 answer
  • Write a function called sum_scores. It should take four arguments, where each argument is the team's score for that quarter. It
    6·1 answer
  • A summer camp offers a morning session and an afternoon session.
    5·1 answer
  • Write the state of the elements of each of the following arrays after each pass of the outermost loop of the selection sort algo
    11·1 answer
  • You are working on a documentation file userNotes.txt with some members of your software development team. Just before the file
    12·1 answer
  • Suppose a switch is built using a computer work station and that it can forward packets at a rate of 500,000 packets per second,
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!