shivamisone

cube number add digit then compare

Dec 7th, 2023
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * cube
  5.  */
  6. public class cube {
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner sc = new Scanner(System.in);
  10.         System.out.println("enter a numeber"); // taking input from user
  11.         int a = sc.nextInt();
  12.         cube ob = new cube();
  13.         ob.chekc(a);
  14.     }
  15.  
  16.     void chekc(int a) {
  17.         int l = a * a * a; // cuubing the number
  18.         int sum = 0;
  19.         while (l != 0) {
  20.             sum += l % 10;
  21.             l = l / 10;
  22.         }
  23.         if (sum == a) { // checking for number
  24.             System.out.println("sum of digits of cube is number");
  25.         } else
  26.             System.out.println("sum of digits of cube is not number");
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment