+ 1

How do you code out 2 different results with out it all showing up in one output

I want to code one result for question 1 and a different result for question to but when I code it it pops up as the out put for every question

6th Nov 2021, 1:22 PM
Crownedthain
10 Answers
+ 9
Your code is not supposed to be written to pass specific test cases... The test cases are just there to validate that your code sums up two variables correctly. The input for each test case will automatically be redirected into the input stream, and be read by the scanner calls. There is no need to insert x and y into your code. Just do: int result1 = salary1 + salary2; System.out.println(result1);
6th Nov 2021, 1:45 PM
Hatsy Rei
Hatsy Rei - avatar
+ 4
devin Wardrup See. . A nice someone is always there to help. When the question is clear. Hatsy Rei well done 👍
6th Nov 2021, 1:51 PM
Emms
Emms - avatar
+ 1
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); //get salaries int salary1 = scanner.nextInt(); int salary2 = scanner.nextInt(); //your code goes here int x = 1500; int y = 3200; int result1 = x+y; System.out.println(result1); int x = 1200; int y = 1900; int result2 = x+y; System.put.println(result2) } } This is code question is You have 2 employees write program to add both salaries Test case 1 1500 and 3200 Test case 2 1200 and 1900 Problem is my output is In both Test cases I don't know how to separate the code for one to go into Test case 1 output and other to go into Test case 2
6th Nov 2021, 1:42 PM
Crownedthain
+ 1
Alright makes sense
6th Nov 2021, 1:46 PM
Crownedthain
+ 1
Only thing is just by coding one answer It doesn't let me pass the test it's as if it wants me to code multiple answers but not in same output
6th Nov 2021, 1:53 PM
Crownedthain
+ 1
devin Wardrup Test cases results depends on your inputs. For different inputs your output maybe change, so you have to write a generic logic which will satisfy all test cases. For example: calculate the sum of two integer value. Test Case1: a = 6 b = 2 Output : 8 Test Case2: a = 10 b = 20 Output : 30 For above cases your code should be look like this: print(a + b) #this is generic logic for both test cases.
6th Nov 2021, 2:02 PM
A͢J
A͢J - avatar
0
Crownedthain What is not working? My example or your own code? I think you didn't understand my explanation or you did something wrong in your code
6th Nov 2021, 5:06 PM
A͢J
A͢J - avatar
0
I figured it out
6th Nov 2021, 7:23 PM
Crownedthain
0
Thanks
6th Nov 2021, 7:23 PM
Crownedthain
- 1
This isn't working for me
6th Nov 2021, 2:58 PM
Crownedthain