top of page
Click here to go to the home page of AskTheCode.

Rambo has Math fear - solution in Java | AskTheCode

Team ATC

Problem Solving in Java | Basic Java Programming Solution | AskTheCode

 

Problem:

Rambo is not good in Mathematics. And, his Math test is happening now in which he's to solve some algebraic expressions. As the test is happening online, so Rambo asked you to help you.


You being a programmer help him to get results of algebraic expressions with the help of a Java program. Rambo has sent you the image of his test questions, help him solve them.

Rambo and Maths Problem Solution in Java

Write a Java for each of the expressions shown above in the picture.


Note: You don't need to take input from the user. He'll put all the values directly.

 

Solutions :

  • For expression m = (a + b + c + d + e) / 5

Sample Input:

  a = 10, b = 20, c = 30, d = 40, e = 40

Sample Output:

  28

Code:

public class Solution{
    public static void main(String []args){
        int a = 10, b = 20, c = 30, d = 40, e = 40;
        int m = (a + b + c + d + e) / 5;
        System.out.println(m);
    }
}
 
  • For expression y = mx + b ^ 2

Sample Input:

  m = 10, x = 5, b = 9

Sample Output:

  131

Code:

 public class Solution{
    public static void main(String []args){
        int m = 10, x = 5, b = 9;
        int y = m * x + (b * b);
        System.out.println(y);
    }
 }
 
  • For expression y = ax ^ 2 + bx + c

Sample Input:

  a = 5, b = 7, c = 4, x = 8

Sample Output:

  380

Code:

 public class Solution{
    public static void main(String []args){
        int a = 5, b = 7, c = 4, x = 8;
        int y = a * (x * x) + b * x + c;
        System.out.println(y);
    }
 }

Recent Posts

See All

Comments

Couldn’t Load Comments
It looks like there was a technical problem. Try reconnecting or refreshing the page.
bottom of page