AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-programming: Dinesh revenge

Dinesh has been bullied enough all his life and now he seeks revenge. His first victim being Deepak, obviously! He found on e question to take revenge from deepak, but without knowing the answers of the question he would not be able to know whether deepak´s answers are correct or not. The question consists of two numbers, a and b, and the answer to it is the sum of digits of a^b (i.e - a raise to the power b). Help him to find the answers so that he can take revenge from deepak. (You should be able to write the solution for this problem in 25 minutes) Input: First line contains the number of test cases t. After that t lines follow each containing a pair of space separated integers i.e. a and b. Output: For each test case, you need to print the sum of digits in a^b. Sample Input : 2 2 10 3 3 Sample Output : 7 9 Explanation Consider the first test case. 2^10 = 1024 Now, 1 + 0 + 2 + 4 = 7 So, output for this test case is 7.

corejava x 351
programming x 167
Posted On : 2016-09-19 15:04:24.0
profile krish soni - anyforum.in krish soni
530
up-rate
5
down-rate

Answers


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class DineshRevenge {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int t=input.nextInt();
List<Integer> outputs= new ArrayList<Integer>();
Double num;
int sum=0;
for(int i=1;i<=t;i++){
sum=0;
num=Math.pow(input.nextInt(), input.nextInt());
outputs.add(num.intValue());
}

for(Integer output:outputs){
for(char digit:output.toString().toCharArray()){
sum=sum+ Integer.valueOf(Character.toString(digit));
}
System.out.println(sum);
}
outputs.clear();
outputs=null;
}
}

Posted On : 2018-06-14 18:55:12
Satisfied : 1 Yes  2 No
profile Garima Gupta - anyforum.in Garima Gupta
596129025113
Reply This Thread
up-rate
0
down-rate

import java.util.Scanner;

public class DeepakRevenge {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int t=input.nextInt();
Double num;
Integer intNum;
int sum;
for(int i=1;i<=t;i++){
sum=0;
num=Math.pow(input.nextInt(), input.nextInt());
intNum=num.intValue();
for(char digit:intNum.toString().toCharArray()){
sum=sum+Integer.parseInt(Character.toString(digit));
}
System.out.print(sum+" ");
}
}
}

Posted On : 2016-09-19 16:52:16
Satisfied : 1 Yes  6 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523187021168
Reply This Thread
up-rate
2
down-rate
Comments
Hey Can you pleas send the coding in Basic Java Format so that i can understand
profile Akash Prasad - anyforum.in Akash Prasad
25  5  0
Posted On :2016-09-20 14:48:49.0
Leave a Comment
This is basic java coding only, what is the challenge??
profile Rishi Kumar - anyforum.in Rishi Kumar
523  1870  21168
Posted On :2016-09-21 22:15:31.0
Leave a Comment

import java.util.Scanner;
import java.lang.Math.*;
public class Abslute
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
double a,b,power=0;
for(int i=0;i<n;i++)
{
a=s.nextInt();
b=s.nextInt();
power=Math.pow(a,b);
int sum=(int)power;
int rem=0,res=0;
for(int j=0;j<n;j++)
{

while (sum > 0)
{
rem = sum % 10;
res = res + rem;
sum = sum / 10;
}

// return;
}
System.out.print(res+" ");
}
}
}
find the below input specification.Let me know if this code is satisfied your specification or not.
Input :
2 2 10 3 3

Output:
7 9


Posted On : 2016-09-20 22:56:25
Satisfied : 1 Yes  6 No
profile Sudheer Kumar Javvadi - anyforum.in Sudheer Kumar Javvadi
0960
Reply This Thread
up-rate
3
down-rate
Comments
Not Satisfied ....my Test Cases are not cleared
profile Akash Prasad - anyforum.in Akash Prasad
25  5  0
Posted On :2016-09-21 15:02:19.0
Leave a Comment
Please give your test case, which got failed. We´ll check.
profile Rishi Kumar - anyforum.in Rishi Kumar
523  1870  21168
Posted On :2016-09-21 22:17:34.0
Leave a Comment
Can you provide clear Test cases for this .As per the given post your specifications are satisfied.
profile Sudheer Kumar Javvadi - anyforum.in Sudheer Kumar Javvadi
0  96  0
Posted On :2016-09-21 22:22:22.0
Leave a Comment
The Test Cases are not provided but we have to pass the all test cases can you please send me another coding.
profile Akash Prasad - anyforum.in Akash Prasad
25  5  0
Posted On :2016-09-21 22:24:35.0
Leave a Comment



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in