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
Plz can someone tell me the answers ?
Ganezh [65]

Answer:

you can

Explanation:

you can

5 0
2 years ago
Read 2 more answers
Explain why you will not do these things when driving.<br><br>yall got one more time to delete it
sesenic [268]
Don't text and drive you could crash
5 0
2 years ago
the two main ways in which marketers address the competition with their strategies are by satisfying a need better than a compet
Nonamiya [84]

Offering a lower price (Apex)

4 0
2 years ago
Read 2 more answers
Java Homework:(The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses nam
miss Akunina [59]

Answer: Wait, so what is the question exactly..?

8 0
3 years ago
You need to install a 32-bit application on a 32-bit version of windows 10. In which default directory will the application be i
luda_lava [24]

Answer:

%systemdrive%\Program Files

7 0
2 years ago
Other questions:
  • • Describe the steps in detail that the operating system performs to handle interrupts, including ISRs, the stack, and hardware?
    5·1 answer
  • Write a program that accepts 5 number and arrange them in ascending order​
    7·1 answer
  • What command is used to generate an RSA key pair?
    9·1 answer
  • The interaction between information technology and organizations is influenced___________.A) solely by the decision making of mi
    12·1 answer
  • Businesses use spreadsheets to keep track of financial________.
    14·1 answer
  • sparse(compact) Description: A sparse matrix is a 2D matrix that has many zeros. Assume that for storage efficiency someone has
    9·1 answer
  • 10010 - 1011 binary subtraction​
    5·1 answer
  • When entering a function or formula in a cell, which is the first character
    15·1 answer
  • Sharon's company has written a new computer program, and she has been asked to find a way to prevent people from copying the sof
    10·1 answer
  • The Linux tail command prints the last maximum n lines of a file. When writing a function that performs this function, choose th
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!