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 ?.



programming-basics: Find the sum of cube of given set of integers

Write a program to calculate the sum of cube of given set of integers.

programming x 164
basics x 169
Posted On : 2016-05-29 15:42:52.0
profile Saksham Kumar - anyforum.in Saksham Kumar
72933914652
up-rate
-3
down-rate

Answers


import java.util.Scanner;

public class SumCube {
public static void main(String[] args) {
System.out.println("Please enter the integers as String. eg. 1, 2, 3 enter 123");
Scanner input=new Scanner(System.in);
String integers=input.nextLine();
double sumCube=0;
for(int i=0;i<integers.length();i++){
sumCube=sumCube+Math.pow(Integer.parseInt(Character.toString(integers.charAt(i))), 3);//calculate the cube of an integer.
}
System.out.println("Total sum of cube of integers= "+sumCube);
}
}


Note:
----------------------------------
don´t use Math.pow(integers.charAt(i), 3). In this case it´ll calculate the cube of ASCII code of that character(integer).

Posted On : 2016-05-29 16:51:39
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523185519807
Reply This Thread
up-rate
5
down-rate



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