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
Inserting and deleting text is a basic editing task in word processing.<br><br> True or false
Katyanochek1 [597]
The answer should be true
3 0
2 years ago
Read 2 more answers
All of the following are incentives proprietary schools use to attract a student except
IRISSAK [1]
Idk what the answer choices are
4 0
3 years ago
Read 2 more answers
Using refracted laser light to store data on a photoreceptive substrate is essentially how ___ storage works. Theoretically this
Alina [70]

Answer:

I try to search the answer but I couldn't find it

4 0
3 years ago
Estoy haciendo codificación en este momento es tan confuso y no estar en la escuela es más difícil
Katarina [22]

Answer:

Misma

Explanation:

6 0
3 years ago
Read 2 more answers
Question 3 (2 points)
jeyben [28]

Answer:

The energy source that does not use heat in the process of converting it to electricity is;

c. Sunlight

Explanation:

In converting Sunlight energy source to electricity, the photons in the light from the Sun excite electrons in the solar cells silicon layers, such that the electrons travel from n-type silicon layer to the p-type silicon layer creating electric potential energy that does work as the electrons flow back in the form of electricity from the p-type to the n-type silicon layer through an external circuit

7 0
3 years ago
Other questions:
  • What is the opportunity cost of computers when moving from point A to point B? -15 DVDs b. What is the opportunity cost of compu
    13·1 answer
  • If you want to tune into a radio station that is carried by a signal with wavelength 3.0 meters, what channel would you choose?
    12·1 answer
  • Which of the following function headings arevalid? If they are invalid, explain why.
    12·1 answer
  • One of your clients has opened a branch office in another state. Both the main office and the new branch office have fast, relia
    10·1 answer
  • Resize vector countDown to have newSize elements. Populate the vector with integers {newSize, newSize - 1, ..., 1}. Ex: If newSi
    6·1 answer
  • Make a list of five primary raw materials, for each one, indicate and industrial material that is created from it
    10·2 answers
  • In the context of computer and network security, a security system is said to possess _____ when it does not allow data to be co
    13·1 answer
  • Which element is represented by the electron configuration in example B? Example B: 1s22s22p63s23p64s1 Aluminum Cesium Potassium
    12·2 answers
  • At a red traffic light, you must stop__
    12·2 answers
  • Question 2 of 10
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!