f

Magic Trick || Newton School assignment solution || Newton School JAVA assignment solution

Magic Trick ||Triangle of height N || Newton school Assignment solution || Newton school assignment Question and answer

I have taken this question from the Newton school assignment so the credit goes to Newton school only.

So if you are first time on my blog please make sure that you also ping a question and solution. if you have a better approach
 
Problem Statement
1. Think of a number X(don't tell Sara)
2. Add A(Given by Sara) to it.
3. Double the sum in your mind.
4. Add an even number B(Given by Sara) to it.
5. Half the amount
6. Subtract the initial number which you had taken from the sum
After this Sara will tell the resulting amount without knowing the initial number, can you print the result for her?
Constraints:-
1 <= A, B <= 1000
3 4
Sara is trying a new magic trick on you, The magic trick goes in 6 steps:-
Input
Input Contains two integers A and B separated by spaces.
Output
Print the resulting amount
Example
Sample Input:-
3 4

Sample Output:-
5

Sample Input:-
8 4

Sample Output:-
10

Magic trick |newton school assignment


import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
}
public static void main (String[] args) {
// Your code here
}
int x=0,y,z;
Scanner sc = new Scanner(System. in);
int an sc.nextInt ();
int b = sc.nextInt ();
z =(a+x);
y =(((2*z)+b)/2)-x;
System.out.println(y);
Let me guys go through this code in the school I have work through the step that Sara has define so in the 1.first step she told you to keep our number into your mind so I just a define one variable and slice with zero after that she told you to add it to your number that you think so the 
2. second step you have to add he in your number what you thinking  your mind after that in the 
3.third step you have to make a sum of your number + the number and in the third step you just have to double the total values after that she gives you another number
4.we just add to the number I mean total number after that make the half of whole values and in the
5. last step you just have to subtract the number this you think initially into your mind I mean X so I just abstract X to the whole values so guys this is the logic that I have implemented into the food using Java programming language so as your student of
 Newton's School you should try this question first and if you are not able to solve this question so you just go through with this code and I hope you get this code and this is very basic you can write the code easily
Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.