+ 1
How do I input 3 numbers using scanner and get the result of 3 corresponding computations? Go to Java lesson 5.1 to see instruct
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); //taking initial score int initScore = scanner.nextInt(); int scoreTom = 5; int scoreBob = 5; System.out.println("Round 1 results:"); System.out.println(++scoreTom); System.out.println(--scoreBob); } } /* I'm also suppose to also type 3 into the consul and the resulted print out is suppose to be 4 and 2 as a result of post/pre increment or post/pre decrement. I don't know how to include that in the code above. Can someone help?
6 Antworten
+ 4
Do not delete the given code, only modify the 2 lines after
// fix
+ 1
If you want to input multiple values, you'll need to repeat your scanner line of code.
You could look up loops and see if that's what you need.
Lesson 5.1 in the Java course only talks about Scanner and you have written that perfectly.
+ 1
Click the dots menu in the code tab. There is a reset option.
Then only modify the 2 lines after // fix
+ 1
amy If you know that the first input value is 5, you don't need user input. You keep your "int scoreTom/Bob = 5;" as it is.
After your final System.out.println, add
System.out.println(++initScore);
System.out.println(--initScore);
Those are both "pre". A post increment/decrement would look like initScore++ / initScore--
0
Can you write code that would get someone's numeral input (in addition to what I've already done) and then do a computational calculation, say like 3 * 5, and print that out to the console. Add it to the code I sent.
0
So, there should be two inputs. One will take an initial score of 5 from both score Tom and score Bob, then it will show the results of a post-increment (++scoreTom) and pre-decrement number (- - scoreBob) printed to the screen.
The second statement will be a single digit input and again we'll have two numbers that are the results of increment or decrement operators.