Skip to content

Commit

Permalink
comit
Browse files Browse the repository at this point in the history
  • Loading branch information
JishnuS420 committed Mar 28, 2024
1 parent 9040bed commit afee5fb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
20 changes: 10 additions & 10 deletions _notebooks/2024-03-19-Student-Lessons-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 3,
"metadata": {
"vscode": {
"languageId": "java"
Expand All @@ -157,22 +157,22 @@
"source": [
"public class GradeAnalyzer {\n",
" \n",
" public double calculateAverageGrade(int[] grades) { // calculate average grade method\n",
" public double calculateAverageGrade(int[] grades) { // calculate average grade method using the array of grades\n",
" int sum = 0; // setting inital sum to 0\n",
" \n",
" for (int grade : grades) { // for grade in the array grades, add the sum with the grade and go to the next\n",
" for (int grade : grades) { // iterating that for grade in the array grades, add the sum with the grade and go to the next\n",
" sum += grade;\n",
" }\n",
" \n",
" double average = (double) sum / grades.length; // divide by array length to get average\n",
" return average;\n",
" }\n",
" \n",
" public static void main(String[] args) { // testing data\n",
" public static void main(String[] args) { // main method for testing data\n",
" int[] studentGrades = {85, 90, 75, 95, 80};\n",
"\n",
" GradeAnalyzer analyzer = new GradeAnalyzer(); // calling method \n",
" double averageGrade = analyzer.calculateAverageGrade(studentGrades);\n",
" GradeAnalyzer analyzer = new GradeAnalyzer(); // creates new instance for the main class\n",
" double averageGrade = analyzer.calculateAverageGrade(studentGrades); // calling method \n",
" \n",
" System.out.println(\"Average Grade: \" + averageGrade);\n",
" }\n",
Expand Down Expand Up @@ -205,7 +205,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 2,
"metadata": {
"vscode": {
"languageId": "java"
Expand All @@ -229,12 +229,12 @@
" return squareRoot;\n",
" }\n",
" \n",
" public static void main(String[] args) { // testing data\n",
" public static void main(String[] args) { // main method to test the data with \n",
"\n",
" double number = 400;\n",
"\n",
" ScientificCalculator calculator = new ScientificCalculator(); // calling method for the calculator\n",
" double squareRoot = calculator.calculateSquareRoot(number);\n",
" ScientificCalculator calculator = new ScientificCalculator(); // creating an instance of the class\n",
" double squareRoot = calculator.calculateSquareRoot(number); // calling method for the calculator\n",
" \n",
" System.out.println(\"Square root of \" + number + \" is: \" + squareRoot);\n",
" }\n",
Expand Down
41 changes: 41 additions & 0 deletions _notebooks/StackHeapTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.nighthawk.hacks;

public class StackHeapTest {
public int n = 5; // Primitive data type
public Integer n1 = 5;
public String n2 = "before";

public static void changeInt(int nValue, int nRefn, StackHeapTest nRef, Integer nInt, String nString) {
System.out.println("\nBefore (Stack):\n");
System.out.println(nValue + " or " + System.identityHashCode(nValue));
System.out.println(nRefn + " or " + System.identityHashCode(nRefn));
System.out.println(nRef + " or " + System.identityHashCode(nRef));

nValue += 10;
nRefn += 10;
nRef.n += 10;

System.out.println("\nAfter (Stack):\n");
System.out.println(nValue + " or " + System.identityHashCode(nValue));
System.out.println(nRefn + " or " + System.identityHashCode(nRefn));
System.out.println(nRef.n + " or " + System.identityHashCode(nRef.n));
}

public static void main(String[] args) {
int nValue = 5;
// int nRef = 5;
StackHeapTest nRef = new StackHeapTest();

System.out.println("\nBefore (Heap):\n");
System.out.println(nValue + " or " + System.identityHashCode(nValue));
System.out.println(nRef + " or " + System.identityHashCode(nRef));
System.out.println(nRef.n + " or " + System.identityHashCode(nRef.n));

changeInt(nValue, nRef.n, nRef);

System.out.println("\nAfter (Heap)\n");
System.out.println(nValue + " or " + System.identityHashCode(nValue));
System.out.println(nRef + " or " + System.identityHashCode(nRef));
System.out.println(nRef.n + " or " + System.identityHashCode(nRef.n));
}
}

0 comments on commit afee5fb

Please sign in to comment.