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]
2 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]2 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
Structure for forloop?
solong [7]

Answer:

for ( initialization; condition;increment)

{

code goes here;

}

in python:

for i in list/range:

code with proper indentation

By initialization above we mean, like int i=0; etc.

By condition like i<10;

and by increment it means like i++, ++i or i+=1; etc

And in python, i can be an integer value if the range is mentioned, and it can be an item of a list if the list is used. We can also use an array, string and various other data structures in python. like we can have characters in a string and so on.

Explanation:

Please check the answer section.

8 0
3 years ago
A common preprocessing step in many natural language processing tasks is text normalization, wherein words are converted to lowe
Arturiano [62]

Answer:

def normalize(text):

   text = text.lower()

   text = text.split()

   return text

Explanation:

The functiinfunction is provided with an input text when called upon, then it changes every character in the text into lower case and split each word with a space.

4 0
3 years ago
One of the newest electronic conveniences is the ________, which can serve as a credit card, a debit card, and even unlock doors
77julia77 [94]
Computer Chips. / SILICON. This is just an educated guess
7 0
3 years ago
Which of the following sets of data would be represented best in histogram?
wariber [46]
I think it would be B. The average monthly sales for the big toy company because its giving data over history
7 0
3 years ago
Read 2 more answers
Jacob would like to include an arrow in his newsletter to point to some important information. He should _____.
qwelly [4]

Some people either add a shape as I do. But for this particular question it would be, either add word art or create a list with bullets. I would rather do word art or insert shape because that means you do not have to get the single bullet.


I really do hope this helped you. I hope you have a great day. And if I am incorrect I apologize.

3 0
3 years ago
Read 2 more answers
Other questions:
  • Thomas Hill claims that a fruitful way to think about the badness of destroying the environment is
    15·1 answer
  • What does the Flippy Do Pro show about representing very small numbers?
    13·1 answer
  • Which type of network cover a large geographical area and usually consists of several smaller networks, which might use differen
    5·1 answer
  • Compare GBN, SR, and TCP (no delayed ACK). Assume that the timeout values for all three protocols are sufficiently long such tha
    7·1 answer
  • If you're doing a relational comparison, which filter would be available?
    15·1 answer
  • The birthday problem is as follows: given a group of n people in a room, what is the probability that two or more of them have t
    15·1 answer
  • How does technology help teach twenty-first century skills?
    5·1 answer
  • Explain the role of a computer in education​
    9·1 answer
  • Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
    6·1 answer
  • What is multimedia computer system​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!