-2

I am required to write a program that adds two numbers. It also requires us to display an error message and terminate the program when more than two numbers are entered by the user. I am a beginner and thus I am having trouble in constructing an IF statement that can terminate the program when more than two integers are entered by the user. For instance in the output:

Please enter two numbers for addition:
2 2 3
Error! System terminating

So how do i make that error message to appear and terminate the program when the user enters more than two integers?

Thanks!

Dejan Skledar
  • 11,280
  • 7
  • 44
  • 70

2 Answers2

0

use System.exit(1); this will terminate the program

Saurabh Jhunjhunwala
  • 2,832
  • 3
  • 29
  • 57
0

Go through this link and read more about String[] args.

Then try to answer your question and post your progress here, if you still face some error.

gopi1410
  • 6,567
  • 9
  • 41
  • 75