BetinaUKTC

7.1

Nov 19th, 2020
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. Factorial
  2. import java.util.Scanner;
  3.  
  4. public class main {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner scan = new Scanner(System.in);
  9.         int n = Integer.parseInt(scan.nextLine());
  10.         int result = 1;
  11.         for (int i = 1; i<=n; i++){
  12.             result = result*i;
  13.         }
  14.         System.out.println(result);
  15.     }
  16. }
  17.  
  18. Sum Digits
  19. import java.util.*;
  20.  
  21. class Main {
  22.  
  23.     public static void main(String[] args) {
  24.         Scanner scan = new Scanner(System.in);
  25.         int a = scan.nextInt();
  26.         int sum = 0;
  27.         while(a>0){
  28.             sum += a%10;
  29.             a/=10;
  30.         }
  31.         System.out.println(sum);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment