Skip to content

Instantly share code, notes, and snippets.

@golenishchev
Last active December 1, 2015 05:55
Show Gist options
  • Save golenishchev/56c6f23cf8d70f164bc2 to your computer and use it in GitHub Desktop.
Save golenishchev/56c6f23cf8d70f164bc2 to your computer and use it in GitHub Desktop.
Lesson 9. Find Max in an Array
class Calculator {
private int firstNumber;
private int secondNumber;
private int resultValue;
private int array;
private double wowSoSquare;
private double numberBeforeSquareRootExtraction;
private double squareRootCalcResult;
private double angleBeforeSineCalc;
private double sineCalcResult;
public int getSum(int firstNumber, int secondNumber) {
return resultValue = firstNumber + secondNumber;
}
public void printResult(int resultValue) {
System.out.println("Result value: " + resultValue);
}
/* BEGIN methods of Math class */
public double getSqrt(double numberBeforeSquareRootExtraction) {
this.numberBeforeSquareRootExtraction = numberBeforeSquareRootExtraction;
return squareRootCalcResult = Math.sqrt(numberBeforeSquareRootExtraction);
}
public double getSine(double angleBeforeSineCalc) {
this.angleBeforeSineCalc = angleBeforeSineCalc;
return sineCalcResult = Math.sin(angleBeforeSineCalc);
}
/* Array */
public void findMaxInAnArray(int[] array) {
int max = array[0];
for(int i = 0; i < array.length; i++){
if(max < array[i])
max = array[i];
}
System.out.println("Maximum in an array: " + max);
}
public static void main(String[] args) {
Calculator myCalc = new Calculator();
int resultValue = myCalc.getSum(10, 5);
myCalc.printResult(resultValue);
myCalc.getSqrt(100.0);
myCalc.getSine(30.0);
int [] array = {12, 1, 5, -11, 7, 13, -1, -5};
myCalc.findMaxInAnArray(array);
System.out.println("The square root of \"" + myCalc.numberBeforeSquareRootExtraction + "\" is: " + myCalc.squareRootCalcResult);
System.out.println("The sine of \"" + myCalc.angleBeforeSineCalc + "\" is: " + myCalc.sineCalcResult);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment