0% found this document useful (0 votes)
11 views2 pages

гараба дз на 18.02

Uploaded by

Garaba Maks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

гараба дз на 18.02

Uploaded by

Garaba Maks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1 take

public class Calculator {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter the first number: ");


double num1 = scanner.nextDouble();

System.out.print("Enter an operator (+, -, *, /): ");


char operator = scanner.next().charAt(0);

System.out.print("Enter the second number: ");


double num2 = scanner.nextDouble();

if (operator == '+') {
System.out.println("Result: " + (num1 + num2));
} else if (operator == '-') {
System.out.println("Result: " + (num1 - num2));
} else if (operator == '*') {
System.out.println("Result: " + (num1 * num2));
} else if (operator == '/') {
if (num2 != 0) {
System.out.println("Result: " + (num1 / num2));
} else {
System.out.println("Error: Division by zero!");
}
} else {
System.out.println("Error: Invalid operator!");
}
}
}

2 take

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter a number (N): ");


int n = scanner.nextInt();

for (int i = 1; i <= 10; i++) {


System.out.println(n + " * " + i + " = " + (n * i));
}
}
}

3 take

public class SumNumbers {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter a number (N): ");


int n = scanner.nextInt();

int sum = 0;
for (int i = 1; i <= n; i++) {
sum += i;
}

System.out.println("Sum of numbers from 1 to " + n + " = " + sum);


}
}

You might also like