Coding Type Question
Marks : 20 Negative Marks : 0
Given two integers a and b, multiply a with 2, b times and print the resultant value.
Input format
Two space-separated integers a and b
Output format
Resultant value
Sample testcases
Input 1
Output 1
5 3
40
in java
Answers
Answered by
0
Answer:
import java.util.Scanner;
import java.util.*;
import java.lang.Math;
public class Main {
/* Driver program */
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Input first number: ");
// take the first number;
int a= in.nextInt();
System.out.print("Input second number: ");
// Take the second number
int b= in.nextInt();
// Returns 2 raised to power b
double c = Math.pow(2, b);
double r =(double)a * c;
System.out.println(r);
}
}
Explanation:
- The above program will take two integers a and b, multiply a with 2, b times and print the resultant value r .
- The Math.pow(2, b) will returns the value of 2 raised to power b.
Similar questions