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
bazaltina [42]
3 years ago
14

Write a method that accepts an integer argument and returns the sum of all the integers from 1 up to (and including) the number

passed as an argument. For example, if 3 is passed as an argument, the method will return the sum of 1+2+3, which is 6. Use recursion to calculate the sum. Test your method in main by prompting the user to enter a positive integer to sum up to. Provide input validation so that only positive values are accepted.
Computers and Technology
1 answer:
kakasveta [241]3 years ago
8 0

Answer:

mark me brainlist

Explanation:

import java.util.*;

public class Main {

       public static int sumOfNumbers(int n)

       {

               if(n==0) return 0;

               else

               return n+sumOfNumbers(n-1);

       }

       public static void main(String[] args) {

               Scanner sc=new Scanner(System.in);

               int n;

               while(true)

               {

                       System.out.println("Enter a number :");

                       n=sc.nextInt();

                       if(n<=0)

                       System.out.println("Enter a positive number ");

                       else

                       break;

               }

               System.out.println("Sum of all numbers upto "+n+" is :"+sumOfNumbers(n));

       }

}

You might be interested in
In securing the client/server environment of an information system, a principal disadvantage of using a single level sign-on
podryga [215]

Answer:

C

Explanation:

7 0
3 years ago
Task1: #Define a function called show_students which takes 2 parameters students and message #Print out a message, and then the
k0ka [10]

Answer:

  1. def show_students(message, sList):
  2.    print(message)
  3.    print(sList)
  4.    print("Our students are currently in alphabetical order")
  5.    sList.sort()
  6.    output = ""
  7.    for student in sList:
  8.        output += "-" + student
  9.    print(output)
  10.    print("Our students are currently in reverse alphabetical order")
  11.    sList.sort(reverse=True)
  12.    output = ""
  13.    for student in sList:
  14.        output += "-" + student
  15.    print(output)  
  16. show_students("Welcome to new semester!", ["Aaron","Bernice", "Cody"])

Explanation:

Firstly we declare a function that will take two inputs, message and student list (Line 1).

In the function, we first print the message and the original input student list (Line 2 - 3). Next, we use sort method to sort the input list and then output the sorted items from the list using a for loop (Line 5-10).

Next, we sort the list again by setting reverse = True and this will sort the list in descending order (Line 13). Again we use the similar way mentioned above to output the sorted items (in descending order) using a for loop (Line 14 -17)

We test the function using a sample student list (Line 18) and we shall get the output:

Welcome to new semester!

['Aaron', 'Bernice', 'Cody']

Our students are currently in alphabetical order

-Aaron-Bernice-Cody

Our students are currently in reverse alphabetical order

-Cody-Bernice-Aaron

6 0
3 years ago
When is the POST process executed?
Olin [163]

Answer:

Below:

Explanation:

A power-on self-test (POST) is a process performed by firmware or software routines immediately after a computer or other digital electronic device is powered on.

Hope it helps.... Bro/Sis

It's Muska...  :)

3 0
3 years ago
What is web <br>searching engine ?​
Nikolay [14]
A Web search engine is a specialized computer server that searches for information on the Web. The search results of a user query are often returned as a list. The hits may consist of web pages, images, and other types of files.
4 0
3 years ago
How does a Cloud-first strategy approach a client's migration to the Cloud?by removing outside ecosystem partners from the Cloud
belka [17]

Cloud-first strategies are <em>operating methods</em> wherein teams move all or most of their infrastructure to <em>cloud computing systems</em><em>  </em>such as Web Services, and the further discussion can be defined as follows:

  • It stores assets, including quest and <em>secure resources</em>, in the cloud rather than employing <em>physical resources</em> including such server clusters.
  • This approaches a client's migration to the <em>Cloud by integrating multiple services </em>together to serve the client's business needs.

Therefore, the final answer is "Last choice".

Learn more:

brainly.com/question/1256812

3 0
3 years ago
Other questions:
  • The number of pixels displayed on the screen is known as ________.
    14·1 answer
  • With iteration-control systems, each team member ________. is given an account with a set of permissions is given their own priv
    6·1 answer
  • Individuals who require better speed and performance for graphics-intensive applications (e.g., video editing, gaming, etc.) pre
    8·1 answer
  • PLEASE HELP ASAP<br> Which technology encrypts traffic between a web browser and a website?
    10·2 answers
  • Which function works best when you need to remove an element at a pacific index and a list
    15·1 answer
  • You want to deploy a software package that's available to all users in the domain if they want to use it, but you don't want the
    7·1 answer
  • What are the values of a[k] and a[k+1] after code corresponding to the following pseudocode runs?
    9·2 answers
  • According to the domain name system (DNS), which of the following is a subdomain of the domain example.com?
    7·2 answers
  • In python,
    15·1 answer
  • What is a program answer these question<br>of grade-6​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!