Prompt the user for a number x and output the sum of all numbers from 1 to x. If the number entered it less than zero, output an error message. Write a code in Java that will result like test case examples

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter1: An Overview Of Computers And Programming Languages
Section: Chapter Questions
Problem 18SA: 18. Tom and Jerry opened a new lawn service. They provide three types of services: mowing,...
icon
Related questions
Question
Prompt the user for a number x and output the sum of all numbers from 1 to x. If the number entered it less than zero, output an error message. Write a code in Java that will result like test case examples .
Test Case 6
Enter a positive, non-zero integer \n
1 ENTER
Sum of numbers from1 to 1 is 1 \n
Test Case 7
Enter a positive, non-zero integer \n
0JENTER
Hey, I said non-zero \n
Test Case 8
Enter a positive, non-zero integer \n
-1 ENTER
Hey, I said positive \n
Test Case 9
Enter a positive, non -zero integer|\n
-97403 ENTER
Hey, I said positive \n
Transcribed Image Text:Test Case 6 Enter a positive, non-zero integer \n 1 ENTER Sum of numbers from1 to 1 is 1 \n Test Case 7 Enter a positive, non-zero integer \n 0JENTER Hey, I said non-zero \n Test Case 8 Enter a positive, non-zero integer \n -1 ENTER Hey, I said positive \n Test Case 9 Enter a positive, non -zero integer|\n -97403 ENTER Hey, I said positive \n
Test Case 1
Enter a positive, non-zero integer \n
5 ENTER
Sum of numbers from
to 5 is 15 \n
Test Case 2
Enter a positive, non-zero integer \n
500 ENTER
Sum of numbers from 1 to 500 is 125250 \n
Test Case 3
Enter a positive, non-zero integer \n
4000 ENTER
Sum of numbers from 1 to 4000 is 8002000 \n
Test Case 4
Enter a positive, non-zero integer \n
22 ENTER
Sum of numbers from 1 to 22 is 253 \n
Test Case 5
Enter a positive, non-zero integer \n
Transcribed Image Text:Test Case 1 Enter a positive, non-zero integer \n 5 ENTER Sum of numbers from to 5 is 15 \n Test Case 2 Enter a positive, non-zero integer \n 500 ENTER Sum of numbers from 1 to 500 is 125250 \n Test Case 3 Enter a positive, non-zero integer \n 4000 ENTER Sum of numbers from 1 to 4000 is 8002000 \n Test Case 4 Enter a positive, non-zero integer \n 22 ENTER Sum of numbers from 1 to 22 is 253 \n Test Case 5 Enter a positive, non-zero integer \n
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Enhanced Discovering Computers 2017 (Shelly Cashm…
Enhanced Discovering Computers 2017 (Shelly Cashm…
Computer Science
ISBN:
9781305657458
Author:
Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Publisher:
Cengage Learning
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning