SlideShare uma empresa Scribd logo
1 de 4
Baixar para ler 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
____________________________________________

Mais conteúdo relacionado

Semelhante a SumOfTwoLargestElements3D.javapublic class SumOfTwoLargestElements.pdf

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
fashioncollection2
 
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
aromanets
 
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
aquacareser
 
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
worldchannel
 

Semelhante a SumOfTwoLargestElements3D.javapublic class SumOfTwoLargestElements.pdf (20)

Lec2
Lec2Lec2
Lec2
 
Lec2&3_DataStructure
Lec2&3_DataStructureLec2&3_DataStructure
Lec2&3_DataStructure
 
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
 

Mais de 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 .pdf
ankitcomputer11
 
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
ankitcomputer11
 
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
ankitcomputer11
 
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
ankitcomputer11
 

Mais de 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
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Último (20)

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

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 ____________________________________________