Skip to content

Commit

Permalink
Updated version.
Browse files Browse the repository at this point in the history
  • Loading branch information
random1223 committed Oct 13, 2024
1 parent 98d1c92 commit f50c6c3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
64 changes: 64 additions & 0 deletions code-issue-examples/java-pmd/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import java.util.Scanner;

public class Calculator {

// Method to perform addition
public static double add(double num1, double num2) {
return num1 + num2;
}

// Method to perform subtraction
public static double subtract(double num1, double num2) {
return num1 - num2;
}

// Method to perform multiplication
public static double multiply(double num1, double num2) {
return num1 * num2;
}

// Method to perform division
public static double divide(double num1, double num2) {
if (num2 == 0) {
System.out.println("Error! Division by zero is not allowed.");
return 0;
}
return num1 / num2;
}

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

System.out.println("Welcome to the Calculator!");
System.out.println("Enter first number: ");
double num1 = scanner.nextDouble();

System.out.println("Enter second number: ");
double num2 = scanner.nextDouble();

System.out.println("Choose operation: +, -, *, /");
char operation = scanner.next().charAt(0);

double result = 0;

switch (operation) {
case '+':
result = add(num1, num2);
break;
case '-':
result = subtract(num1, num2);
break;
case '*':
result = multiply(num1, num2);
break;
case '/':
result = divide(num1, num2);
break;
default:
System.out.println("Invalid operation!");
return;
}

System.out.println("The result is: " + result);
}
}
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
rootProject.name = "codety-scanner"

include 'code-issue-examples'
include 'image'
include 'scanner-common'
include 'scanner'
include 'analyzer-codety'
Expand Down

0 comments on commit f50c6c3

Please sign in to comment.