Advertisement
Mancolo

Домашняя работа 14 - Методы

Mar 31st, 2021
1,168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {
  7.         int l = 0;
  8.         System.out.println("Первые 100 прямоугольные числа, 10 на строку");
  9.         for (int i = 0; i < 100; i++) {
  10.             System.out.printf("%7s", getPentagonalNumber(i));
  11.             l++;
  12.             if (l == 10) {
  13.                 System.out.println();
  14.                 l = 0;
  15.             }
  16.         }
  17.         int a, b, c, d;
  18.         Scanner in = new Scanner(System.in);
  19.         int[] array = new int[4];
  20.         System.out.println("Введите 1ое число:");
  21.         a = in.nextInt();
  22.         System.out.println("Введите 2ое число:");
  23.         b = in.nextInt();
  24.         System.out.println("Введите 3ое число:");
  25.         c = in.nextInt();
  26.         System.out.println("Введите 4ое число:");
  27.         d = in.nextInt();
  28.         array[0] = a;
  29.         array[1] = b;
  30.         array[2] = c;
  31.         array[3] = d;
  32.         System.out.printf("Your result is: %d", SearchMath(array));
  33.     }
  34.  
  35.     public static int SearchMath(int[] someArray) {
  36.         int l = 0;
  37.  
  38.         for (int j : someArray) {
  39.             if (l < j) {
  40.                 l = j;
  41.             }
  42.         }
  43.  
  44.         return l;
  45.     }
  46.  
  47.     public static int getPentagonalNumber(int n) {
  48.         return n * (3 * n - 1) / 2;
  49.     }
  50.     {
  51.         System.out.print("Enter your number: ");
  52.         Scanner in = new Scanner(System.in);
  53.  
  54.         int a = in.nextInt();
  55.         System.out.printf("Sum of digits is %d", sumDigits(a));
  56. }
  57.     static int sumDigits(int n) {
  58.         int sum = 0;
  59.         while (n != 0) {
  60.             sum += (n % 10);
  61.             n /= 10;
  62.         }
  63.         return sum;
  64.     }
  65.  
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement