SlideShare a Scribd company logo
1 of 4
Download to read offline
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);
//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
____________________________________________

More Related Content

Similar to SumOfTwoLargestElements3D.javapublic class SumOfTwoLargestElements.pdf

Lec2&3 data structure
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structureSaad Gabr
 
Write a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdfWrite a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdffashioncollection2
 
C# features through examples
C# features through examplesC# features through examples
C# features through examplesZayen Chagra
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfaromanets
 
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdfimport java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdfaquacareser
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyworldchannel
 

Similar to SumOfTwoLargestElements3D.javapublic class SumOfTwoLargestElements.pdf (20)

Lec2&3 data structure
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structure
 
Lec2
Lec2Lec2
Lec2
 
Write a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdfWrite a method called uniqueNumbers that takes an int array as param.pdf
Write a method called uniqueNumbers that takes an int array as param.pdf
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Java arrays
Java    arraysJava    arrays
Java arrays
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
 
Array BPK 2
Array BPK 2Array BPK 2
Array BPK 2
 
C# features through examples
C# features through examplesC# features through examples
C# features through examples
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
 
Lec2&3 data structure
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structure
 
Lec2
Lec2Lec2
Lec2
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
Chap1 array
Chap1 arrayChap1 array
Chap1 array
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
 
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdfimport java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
 
Ch5 array nota
Ch5 array notaCh5 array nota
Ch5 array nota
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
 
ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.ppt
 

More from ankitcomputer11

#includestdio.h#includestdlib.h structure of a stack node .pdf
#includestdio.h#includestdlib.h structure of a stack node .pdf#includestdio.h#includestdlib.h structure of a stack node .pdf
#includestdio.h#includestdlib.h structure of a stack node .pdfankitcomputer11
 
Solution Since we know that the subshell with .pdf
                     Solution Since we know that the subshell with  .pdf                     Solution Since we know that the subshell with  .pdf
Solution Since we know that the subshell with .pdfankitcomputer11
 
let V be nonempty open subset of X then V inters.pdf
                     let V be nonempty open subset of X  then V inters.pdf                     let V be nonempty open subset of X  then V inters.pdf
let V be nonempty open subset of X then V inters.pdfankitcomputer11
 
Look at the periodic table. When Be loses its f.pdf
                     Look at the periodic table. When Be loses its f.pdf                     Look at the periodic table. When Be loses its f.pdf
Look at the periodic table. When Be loses its f.pdfankitcomputer11
 
taking L.T.,,,,,,,,,,,,Y(s)[s^2+4s+14]=L(T(t))....pdf
                     taking L.T.,,,,,,,,,,,,Y(s)[s^2+4s+14]=L(T(t))....pdf                     taking L.T.,,,,,,,,,,,,Y(s)[s^2+4s+14]=L(T(t))....pdf
taking L.T.,,,,,,,,,,,,Y(s)[s^2+4s+14]=L(T(t))....pdfankitcomputer11
 
the salt is neutral in charge. OS of Ca is +2, so.pdf
                     the salt is neutral in charge. OS of Ca is +2, so.pdf                     the salt is neutral in charge. OS of Ca is +2, so.pdf
the salt is neutral in charge. OS of Ca is +2, so.pdfankitcomputer11
 
nonmetals, metals, metalloids, and gases. They ar.pdf
                     nonmetals, metals, metalloids, and gases. They ar.pdf                     nonmetals, metals, metalloids, and gases. They ar.pdf
nonmetals, metals, metalloids, and gases. They ar.pdfankitcomputer11
 
x= 2 (or) -2Solutionx= 2 (or) -2.pdf
x= 2 (or) -2Solutionx= 2 (or) -2.pdfx= 2 (or) -2Solutionx= 2 (or) -2.pdf
x= 2 (or) -2Solutionx= 2 (or) -2.pdfankitcomputer11
 
there are two types that are presented as ch3 and ch...Solution.pdf
there are two types that are presented as ch3 and ch...Solution.pdfthere are two types that are presented as ch3 and ch...Solution.pdf
there are two types that are presented as ch3 and ch...Solution.pdfankitcomputer11
 
In thermodynamics, a state function, function of .pdf
                     In thermodynamics, a state function, function of .pdf                     In thermodynamics, a state function, function of .pdf
In thermodynamics, a state function, function of .pdfankitcomputer11
 
The process of protein synthesis and secretion starts from the endop.pdf
The process of protein synthesis and secretion starts from the endop.pdfThe process of protein synthesis and secretion starts from the endop.pdf
The process of protein synthesis and secretion starts from the endop.pdfankitcomputer11
 
The IUPAC names of the given compounds is      2-chloro-1-butanol.pdf
The IUPAC names of the given compounds is      2-chloro-1-butanol.pdfThe IUPAC names of the given compounds is      2-chloro-1-butanol.pdf
The IUPAC names of the given compounds is      2-chloro-1-butanol.pdfankitcomputer11
 
Solution - (c) - 20001 SharesCalculation of Number of shares to be.pdf
Solution - (c) - 20001 SharesCalculation of Number of shares to be.pdfSolution - (c) - 20001 SharesCalculation of Number of shares to be.pdf
Solution - (c) - 20001 SharesCalculation of Number of shares to be.pdfankitcomputer11
 
NOBecause here we are not working on past experience of data.S.pdf
NOBecause here we are not working on past experience of data.S.pdfNOBecause here we are not working on past experience of data.S.pdf
NOBecause here we are not working on past experience of data.S.pdfankitcomputer11
 
Move decimal to behind the first number4.71Round4.714.71 X 1.pdf
Move decimal to behind the first number4.71Round4.714.71 X 1.pdfMove decimal to behind the first number4.71Round4.714.71 X 1.pdf
Move decimal to behind the first number4.71Round4.714.71 X 1.pdfankitcomputer11
 
Lewis acid is the electron pair acceptorLewis base is the electron.pdf
Lewis acid is the electron pair acceptorLewis base is the electron.pdfLewis acid is the electron pair acceptorLewis base is the electron.pdf
Lewis acid is the electron pair acceptorLewis base is the electron.pdfankitcomputer11
 
first treat with alcoholic KOH to get cyclo hexene and then treat it.pdf
first treat with alcoholic KOH to get cyclo hexene and then treat it.pdffirst treat with alcoholic KOH to get cyclo hexene and then treat it.pdf
first treat with alcoholic KOH to get cyclo hexene and then treat it.pdfankitcomputer11
 
An azeotrope is a mixture of two or more liquids .pdf
                     An azeotrope is a mixture of two or more liquids .pdf                     An azeotrope is a mixture of two or more liquids .pdf
An azeotrope is a mixture of two or more liquids .pdfankitcomputer11
 
Here we have sodium bisulfate NaHSO4, as you have shown the ions pr.pdf
Here we have sodium bisulfate NaHSO4, as you have shown the ions pr.pdfHere we have sodium bisulfate NaHSO4, as you have shown the ions pr.pdf
Here we have sodium bisulfate NaHSO4, as you have shown the ions pr.pdfankitcomputer11
 

More from ankitcomputer11 (20)

#includestdio.h#includestdlib.h structure of a stack node .pdf
#includestdio.h#includestdlib.h structure of a stack node .pdf#includestdio.h#includestdlib.h structure of a stack node .pdf
#includestdio.h#includestdlib.h structure of a stack node .pdf
 
Solution Since we know that the subshell with .pdf
                     Solution Since we know that the subshell with  .pdf                     Solution Since we know that the subshell with  .pdf
Solution Since we know that the subshell with .pdf
 
let V be nonempty open subset of X then V inters.pdf
                     let V be nonempty open subset of X  then V inters.pdf                     let V be nonempty open subset of X  then V inters.pdf
let V be nonempty open subset of X then V inters.pdf
 
Look at the periodic table. When Be loses its f.pdf
                     Look at the periodic table. When Be loses its f.pdf                     Look at the periodic table. When Be loses its f.pdf
Look at the periodic table. When Be loses its f.pdf
 
taking L.T.,,,,,,,,,,,,Y(s)[s^2+4s+14]=L(T(t))....pdf
                     taking L.T.,,,,,,,,,,,,Y(s)[s^2+4s+14]=L(T(t))....pdf                     taking L.T.,,,,,,,,,,,,Y(s)[s^2+4s+14]=L(T(t))....pdf
taking L.T.,,,,,,,,,,,,Y(s)[s^2+4s+14]=L(T(t))....pdf
 
the salt is neutral in charge. OS of Ca is +2, so.pdf
                     the salt is neutral in charge. OS of Ca is +2, so.pdf                     the salt is neutral in charge. OS of Ca is +2, so.pdf
the salt is neutral in charge. OS of Ca is +2, so.pdf
 
nonmetals, metals, metalloids, and gases. They ar.pdf
                     nonmetals, metals, metalloids, and gases. They ar.pdf                     nonmetals, metals, metalloids, and gases. They ar.pdf
nonmetals, metals, metalloids, and gases. They ar.pdf
 
x= 2 (or) -2Solutionx= 2 (or) -2.pdf
x= 2 (or) -2Solutionx= 2 (or) -2.pdfx= 2 (or) -2Solutionx= 2 (or) -2.pdf
x= 2 (or) -2Solutionx= 2 (or) -2.pdf
 
there are two types that are presented as ch3 and ch...Solution.pdf
there are two types that are presented as ch3 and ch...Solution.pdfthere are two types that are presented as ch3 and ch...Solution.pdf
there are two types that are presented as ch3 and ch...Solution.pdf
 
In thermodynamics, a state function, function of .pdf
                     In thermodynamics, a state function, function of .pdf                     In thermodynamics, a state function, function of .pdf
In thermodynamics, a state function, function of .pdf
 
The process of protein synthesis and secretion starts from the endop.pdf
The process of protein synthesis and secretion starts from the endop.pdfThe process of protein synthesis and secretion starts from the endop.pdf
The process of protein synthesis and secretion starts from the endop.pdf
 
The IUPAC names of the given compounds is      2-chloro-1-butanol.pdf
The IUPAC names of the given compounds is      2-chloro-1-butanol.pdfThe IUPAC names of the given compounds is      2-chloro-1-butanol.pdf
The IUPAC names of the given compounds is      2-chloro-1-butanol.pdf
 
Solution - (c) - 20001 SharesCalculation of Number of shares to be.pdf
Solution - (c) - 20001 SharesCalculation of Number of shares to be.pdfSolution - (c) - 20001 SharesCalculation of Number of shares to be.pdf
Solution - (c) - 20001 SharesCalculation of Number of shares to be.pdf
 
NOBecause here we are not working on past experience of data.S.pdf
NOBecause here we are not working on past experience of data.S.pdfNOBecause here we are not working on past experience of data.S.pdf
NOBecause here we are not working on past experience of data.S.pdf
 
Move decimal to behind the first number4.71Round4.714.71 X 1.pdf
Move decimal to behind the first number4.71Round4.714.71 X 1.pdfMove decimal to behind the first number4.71Round4.714.71 X 1.pdf
Move decimal to behind the first number4.71Round4.714.71 X 1.pdf
 
Lewis acid is the electron pair acceptorLewis base is the electron.pdf
Lewis acid is the electron pair acceptorLewis base is the electron.pdfLewis acid is the electron pair acceptorLewis base is the electron.pdf
Lewis acid is the electron pair acceptorLewis base is the electron.pdf
 
CsSolutionCs.pdf
CsSolutionCs.pdfCsSolutionCs.pdf
CsSolutionCs.pdf
 
first treat with alcoholic KOH to get cyclo hexene and then treat it.pdf
first treat with alcoholic KOH to get cyclo hexene and then treat it.pdffirst treat with alcoholic KOH to get cyclo hexene and then treat it.pdf
first treat with alcoholic KOH to get cyclo hexene and then treat it.pdf
 
An azeotrope is a mixture of two or more liquids .pdf
                     An azeotrope is a mixture of two or more liquids .pdf                     An azeotrope is a mixture of two or more liquids .pdf
An azeotrope is a mixture of two or more liquids .pdf
 
Here we have sodium bisulfate NaHSO4, as you have shown the ions pr.pdf
Here we have sodium bisulfate NaHSO4, as you have shown the ions pr.pdfHere we have sodium bisulfate NaHSO4, as you have shown the ions pr.pdf
Here we have sodium bisulfate NaHSO4, as you have shown the ions pr.pdf
 

Recently uploaded

ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxheathfieldcps1
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Celine George
 
Discover the Dark Web .pdf InfosecTrain
Discover the Dark Web .pdf  InfosecTrainDiscover the Dark Web .pdf  InfosecTrain
Discover the Dark Web .pdf InfosecTraininfosec train
 
Essential Safety precautions during monsoon season
Essential Safety precautions during monsoon seasonEssential Safety precautions during monsoon season
Essential Safety precautions during monsoon seasonMayur Khatri
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...Nguyen Thanh Tu Collection
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the lifeNitinDeodare
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/siemaillard
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticspragatimahajan3
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17Celine George
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesashishpaul799
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxCeline George
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Celine George
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff17thcssbs2
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
factors influencing drug absorption-final-2.pptx
factors influencing drug absorption-final-2.pptxfactors influencing drug absorption-final-2.pptx
factors influencing drug absorption-final-2.pptxSanjay Shekar
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxNehaChandwani11
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya - UEM Kolkata Quiz Club
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatmentsaipooja36
 

Recently uploaded (20)

ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
Discover the Dark Web .pdf InfosecTrain
Discover the Dark Web .pdf  InfosecTrainDiscover the Dark Web .pdf  InfosecTrain
Discover the Dark Web .pdf InfosecTrain
 
Essential Safety precautions during monsoon season
Essential Safety precautions during monsoon seasonEssential Safety precautions during monsoon season
Essential Safety precautions during monsoon season
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
factors influencing drug absorption-final-2.pptx
factors influencing drug absorption-final-2.pptxfactors influencing drug absorption-final-2.pptx
factors influencing drug absorption-final-2.pptx
 
The Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptxThe Ball Poem- John Berryman_20240518_001617_0000.pptx
The Ball Poem- John Berryman_20240518_001617_0000.pptx
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
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 ____________________________________________