Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CompareNumbers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Введите первое число:");
- double number1 = scanner.nextDouble();
- System.out.println("Введите второе число:");
- double number2 = scanner.nextDouble();
- System.out.println("Введите третье число:");
- double number3 = scanner.nextDouble();
- if (number1 == number2 && number2 == number3) {
- System.out.println("3");
- } else if (number1 == number2 || number2 == number3 || number1 == number3) {
- System.out.println("2");
- } else {
- System.out.println("1");
- }
- }
- }
- ///////////////////////////////////////
- import java.util.Scanner;
- public class FactorialSequence {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Введите вещественное число a:");
- double a = scanner.nextDouble();
- double sum = 0;
- int n = 1;
- while (true) {
- double element = factorial(n) / calculateSum(n);
- sum += element;
- if (element > a) {
- System.out.println("Первый элемент последовательности, больший a: " + element);
- break;
- }
- n++;
- }
- }
- private static double factorial(int n) {
- if (n == 0 || n == 1) {
- return 1;
- }
- return n * factorial(n - 1);
- }
- private static double calculateSum(int n) {
- double sum = 0;
- for (int i = 1; i <= n; i++) {
- sum += i;
- }
- return sum;
- }
- }
- /////////////////////////////////////////////////
- import java.util.Scanner;
- import java.util.HashSet;
- import java.util.Set;
- public class UniqueElements {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Введите количество элементов массива:");
- int n = scanner.nextInt();
- int[] array = new int[n];
- System.out.println("Введите значения элементов массива:");
- for (int i = 0; i < n; i++) {
- array[i] = scanner.nextInt();
- }
- int uniqueCount = countUniqueElements(array);
- System.out.println("Количество различных значений элементов массива: " + uniqueCount);
- }
- private static int countUniqueElements(int[] array) {
- Set<Integer> uniqueSet = new HashSet<>();
- for (int element : array) {
- uniqueSet.add(element);
- }
- return uniqueSet.size();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement