Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- int l = 0;
- System.out.println("Первые 100 прямоугольные числа, 10 на строку");
- for (int i = 0; i < 100; i++) {
- System.out.printf("%7s", getPentagonalNumber(i));
- l++;
- if (l == 10) {
- System.out.println();
- l = 0;
- }
- }
- int a, b, c, d;
- Scanner in = new Scanner(System.in);
- int[] array = new int[4];
- System.out.println("Введите 1ое число:");
- a = in.nextInt();
- System.out.println("Введите 2ое число:");
- b = in.nextInt();
- System.out.println("Введите 3ое число:");
- c = in.nextInt();
- System.out.println("Введите 4ое число:");
- d = in.nextInt();
- array[0] = a;
- array[1] = b;
- array[2] = c;
- array[3] = d;
- System.out.printf("Your result is: %d", SearchMath(array));
- }
- public static int SearchMath(int[] someArray) {
- int l = 0;
- for (int j : someArray) {
- if (l < j) {
- l = j;
- }
- }
- return l;
- }
- public static int getPentagonalNumber(int n) {
- return n * (3 * n - 1) / 2;
- }
- {
- System.out.print("Enter your number: ");
- Scanner in = new Scanner(System.in);
- int a = in.nextInt();
- System.out.printf("Sum of digits is %d", sumDigits(a));
- }
- static int sumDigits(int n) {
- int sum = 0;
- while (n != 0) {
- sum += (n % 10);
- n /= 10;
- }
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement