Hey, everyone. I am a complete beginner and been wanting to learn a programming skill since I was a kid back in the 90's. I guess it's never to late. Anyways, I stumbled on this website (hyperkill.org) and I need some help they kind of go to the test of being really easy to complete hard and I don't have the skill. But, still want to try and learn it so I am not giving up. Here is the problem they are asking me.
Write a program that reads four numbers and decrements each of them.
The program must output the results in the same order separated by spaces.
Sample Input 1:
10 11 -2 -3
Sample Output 1:
9 10 -3 -4
I think I understand how to decrement, I understand how to get the numbers by using int a,b,c,d and a = 10, b = 11, c = -2, d = -3 (unless I am using variable wrong) then somehow use --a, and so forth to print out, but they want me to also include the spaces but they never teach you that. I don't know if I am completely understanding this at all. I don't want any answers just some help would be nice.
Not surprised. They gave you sample input so you have a better idea of what your program needs to do. The idea is take any 4 numbers and decrement each one. The test probably gave you totally different numbers so naturally your program failed the test.
You could use a Scanner and .nextInt() -- you could also check to see if args has 4 elements in it and iterate over it if it does. You never know how your program will be called. Most likely that Scanner will do the job though.