SumOfTwoLargestElements3D.java
public class SumOfTwoLargestElements3D {
public static void main(String[] args) {
// Declaring 3-Dimensional Array
int c[][][] = new int[][][] {
{ { 1, 2, 3 }, { 2, 4, 5 }, { 15, 0, 0 } },
{ { 100, 42, 3 }, { 16, 90, 5 }, { 15, 0, 0 } },
{ { 1, 2, 3 }, { 2, 4, 5 }, { 250, 0, 0 } } };
//Calling the method add() by passing the three dimensional array as input.
int sum3 = add(c);
//Displaying the sum of two largest elements in the array.
System.out.println(\"Sum :\"+sum3);
}
/*
* This method will find the sum of two largest elements in the 3D-Array
* Params :Three Dimensional Array
* Return :Sum which is of type integer
*/
private static int add(int[][][] c) {
//Declare the local variables.
int first, second;
//We are assigning values to the \'first\' and and \'second\' variables
if (c[0][0][0] > c[0][0][1]) {
first = c[0][0][0];
second = c[0][0][1];
} else {
first = c[0][0][1];
second = c[0][0][0];
}
//Traverse the array to find the First largest and second elements in the array
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (c[i][j][k] > first) {
second = first;
first = c[i][j][k];
}
else if (c[i][j][k] > second && c[i][j][k] != first)
second = c[i][j][k];
}
}
}
//Displaying the First Highest number
System.out.println(\"First Largest Element :\"+first);
//Displaying the Second Highest number
System.out.println(\"Second Largest Element :\"+second);
return (first + second);
}
}
____________________________________________
Output:
First Largest Element :250
Second Largest Element :100
Sum :350
____________________________________________
Solution
SumOfTwoLargestElements3D.java
public class SumOfTwoLargestElements3D {
public static void main(String[] args) {
// Declaring 3-Dimensional Array
int c[][][] = new int[][][] {
{ { 1, 2, 3 }, { 2, 4, 5 }, { 15, 0, 0 } },
{ { 100, 42, 3 }, { 16, 90, 5 }, { 15, 0, 0 } },
{ { 1, 2, 3 }, { 2, 4, 5 }, { 250, 0, 0 } } };
//Calling the method add() by passing the three dimensional array as input.
int sum3 = add(c);
//Displaying the sum of two largest elements in the array.
System.out.println(\"Sum :\"+sum3);
}
/*
* This method will find the sum of two largest elements in the 3D-Array
* Params :Three Dimensional Array
* Return :Sum which is of type integer
*/
private static int add(int[][][] c) {
//Declare the local variables.
int first, second;
//We are assigning values to the \'first\' and and \'second\' variables
if (c[0][0][0] > c[0][0][1]) {
first = c[0][0][0];
second = c[0][0][1];
} else {
first = c[0][0][1];
second = c[0][0][0];
}
//Traverse the array to find the First largest and second elements in the array
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (c[i][j][k] > first) {
second = first;
first = c[i][j][k];
}
else if (c[i][j][k] > second && c[i][j][k] != first)
second = c[i][j][k];
}
}
}
//Displaying the First Highest number
System.out.println(\"First Largest Element :\"+first);
.
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
SumOfTwoLargestElements3D.javapublic class SumOfTwoLargestElements.pdf
1. SumOfTwoLargestElements3D.java
public class SumOfTwoLargestElements3D {
public static void main(String[] args) {
// Declaring 3-Dimensional Array
int c[][][] = new int[][][] {
{ { 1, 2, 3 }, { 2, 4, 5 }, { 15, 0, 0 } },
{ { 100, 42, 3 }, { 16, 90, 5 }, { 15, 0, 0 } },
{ { 1, 2, 3 }, { 2, 4, 5 }, { 250, 0, 0 } } };
//Calling the method add() by passing the three dimensional array as input.
int sum3 = add(c);
//Displaying the sum of two largest elements in the array.
System.out.println("Sum :"+sum3);
}
/*
* This method will find the sum of two largest elements in the 3D-Array
* Params :Three Dimensional Array
* Return :Sum which is of type integer
*/
private static int add(int[][][] c) {
//Declare the local variables.
int first, second;
//We are assigning values to the 'first' and and 'second' variables
if (c[0][0][0] > c[0][0][1]) {
first = c[0][0][0];
second = c[0][0][1];
} else {
first = c[0][0][1];
second = c[0][0][0];
}
//Traverse the array to find the First largest and second elements in the array
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
2. if (c[i][j][k] > first) {
second = first;
first = c[i][j][k];
}
else if (c[i][j][k] > second && c[i][j][k] != first)
second = c[i][j][k];
}
}
}
//Displaying the First Highest number
System.out.println("First Largest Element :"+first);
//Displaying the Second Highest number
System.out.println("Second Largest Element :"+second);
return (first + second);
}
}
____________________________________________
Output:
First Largest Element :250
Second Largest Element :100
Sum :350
____________________________________________
Solution
SumOfTwoLargestElements3D.java
public class SumOfTwoLargestElements3D {
public static void main(String[] args) {
// Declaring 3-Dimensional Array
int c[][][] = new int[][][] {
{ { 1, 2, 3 }, { 2, 4, 5 }, { 15, 0, 0 } },
{ { 100, 42, 3 }, { 16, 90, 5 }, { 15, 0, 0 } },
{ { 1, 2, 3 }, { 2, 4, 5 }, { 250, 0, 0 } } };
3. //Calling the method add() by passing the three dimensional array as input.
int sum3 = add(c);
//Displaying the sum of two largest elements in the array.
System.out.println("Sum :"+sum3);
}
/*
* This method will find the sum of two largest elements in the 3D-Array
* Params :Three Dimensional Array
* Return :Sum which is of type integer
*/
private static int add(int[][][] c) {
//Declare the local variables.
int first, second;
//We are assigning values to the 'first' and and 'second' variables
if (c[0][0][0] > c[0][0][1]) {
first = c[0][0][0];
second = c[0][0][1];
} else {
first = c[0][0][1];
second = c[0][0][0];
}
//Traverse the array to find the First largest and second elements in the array
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (c[i][j][k] > first) {
second = first;
first = c[i][j][k];
}
else if (c[i][j][k] > second && c[i][j][k] != first)
second = c[i][j][k];
}
}
}
4. //Displaying the First Highest number
System.out.println("First Largest Element :"+first);
//Displaying the Second Highest number
System.out.println("Second Largest Element :"+second);
return (first + second);
}
}
____________________________________________
Output:
First Largest Element :250
Second Largest Element :100
Sum :350
____________________________________________