Skip to content

Instantly share code, notes, and snippets.

@sunmeat
Last active August 6, 2024 07:10
Show Gist options
  • Select an option

  • Save sunmeat/64bf878722004e521838 to your computer and use it in GitHub Desktop.

Select an option

Save sunmeat/64bf878722004e521838 to your computer and use it in GitHub Desktop.
return
package com.alex.methods;
public class JavaApplication1 {
static double megoCalc(double first, char operation, double second) {
switch (operation) {
case '+':
return first + second;
case '-':
return first - second;
case '*':
return first * second;
case '/':
return second != 0 ? first / second : 0;
case '^':
return Math.pow(first, second);
default:
return -1;
}
}
public static void main(String[] args) {
double result = megoCalc(5, '^', 2);
System.out.println(result); // 25
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment