SlideShare a Scribd company logo
Write a static method named numberoddSum that accepts a positive integer returns the sum of
its odd digits. For example, the call numberOddSum (1436527) should return 16.
Solution
Hi, PLease find my implementtion.
Please let me know in case of any issue.
import java.util.Scanner;
public class OddDigitsSum {
public static int numberOddSum(int n){
int sum = 0; // variable to store sum of odd digits
// if n is negative, making it positive
if(n < 0)
n = -n;
while( n > 0){
int digit = n%10; // getting current digit
if(digit % 2 == 1)
sum = sum + digit;
n = n/10;
}
return sum;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a integer: ");
int number = sc.nextInt();
System.out.println("Odd digit sum: "+numberOddSum(number));
}
}
/*
Sample run:
Enter a integer: 4321234
Odd digit sum: 7
*/

More Related Content

Similar to Write a static method named numberoddSum that accepts a positive inte.pdf

CODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfCODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdf
anurag1231
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
Ajenkris Kungkung
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
KimVeeL
 
OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docx
gerardkortney
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
Rahul Pandit
 
CountPositiveNumbersInArray.javapackage org.students;import java.pdf
CountPositiveNumbersInArray.javapackage org.students;import java.pdfCountPositiveNumbersInArray.javapackage org.students;import java.pdf
CountPositiveNumbersInArray.javapackage org.students;import java.pdf
aparnatiwari291
 
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdfQ1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
fathimalinks
 
Oot practical
Oot practicalOot practical
Oot practical
Vipin Rawat @ daya
 

Similar to Write a static method named numberoddSum that accepts a positive inte.pdf (8)

CODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfCODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdf
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
 
OverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docxOverviewThis hands-on lab allows you to follow and experiment w.docx
OverviewThis hands-on lab allows you to follow and experiment w.docx
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
CountPositiveNumbersInArray.javapackage org.students;import java.pdf
CountPositiveNumbersInArray.javapackage org.students;import java.pdfCountPositiveNumbersInArray.javapackage org.students;import java.pdf
CountPositiveNumbersInArray.javapackage org.students;import java.pdf
 
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdfQ1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
Q1. Print all the odd numbers from 1 to a user specifiable upper lim.pdf
 
Oot practical
Oot practicalOot practical
Oot practical
 

More from Dhanrajsolanki2091

Please I need help with this....Please also provide comments in each.pdf
Please I need help with this....Please also provide comments in each.pdfPlease I need help with this....Please also provide comments in each.pdf
Please I need help with this....Please also provide comments in each.pdf
Dhanrajsolanki2091
 
Please give me the origin and history on Hassall’s corpusclesSol.pdf
Please give me the origin and history on Hassall’s corpusclesSol.pdfPlease give me the origin and history on Hassall’s corpusclesSol.pdf
Please give me the origin and history on Hassall’s corpusclesSol.pdf
Dhanrajsolanki2091
 
OBJ. 2 PE 12-2A Dividing partnership net income Han Lee and Monica An.pdf
OBJ. 2 PE 12-2A Dividing partnership net income Han Lee and Monica An.pdfOBJ. 2 PE 12-2A Dividing partnership net income Han Lee and Monica An.pdf
OBJ. 2 PE 12-2A Dividing partnership net income Han Lee and Monica An.pdf
Dhanrajsolanki2091
 
O’Connor says that Aristotelian justice “overcomes misorientation to.pdf
O’Connor says that Aristotelian justice “overcomes misorientation to.pdfO’Connor says that Aristotelian justice “overcomes misorientation to.pdf
O’Connor says that Aristotelian justice “overcomes misorientation to.pdf
Dhanrajsolanki2091
 
Let T R^5 rightarrow R^3 be a linear transformation whose null space.pdf
Let T R^5 rightarrow R^3 be a linear transformation whose null space.pdfLet T R^5 rightarrow R^3 be a linear transformation whose null space.pdf
Let T R^5 rightarrow R^3 be a linear transformation whose null space.pdf
Dhanrajsolanki2091
 
Make drawings of both organisms stained in each staining procedure. L.pdf
Make drawings of both organisms stained in each staining procedure. L.pdfMake drawings of both organisms stained in each staining procedure. L.pdf
Make drawings of both organisms stained in each staining procedure. L.pdf
Dhanrajsolanki2091
 
Link to TextThese selected condensed data are taken from a recent ba.pdf
Link to TextThese selected condensed data are taken from a recent ba.pdfLink to TextThese selected condensed data are taken from a recent ba.pdf
Link to TextThese selected condensed data are taken from a recent ba.pdf
Dhanrajsolanki2091
 
Java Database Connect Write a program that views, inserts, and u.pdf
Java Database Connect Write a program that views, inserts, and u.pdfJava Database Connect Write a program that views, inserts, and u.pdf
Java Database Connect Write a program that views, inserts, and u.pdf
Dhanrajsolanki2091
 
JUST DO QUESTION 32) You have discussed with the human resource ma.pdf
JUST DO QUESTION 32) You have discussed with the human resource ma.pdfJUST DO QUESTION 32) You have discussed with the human resource ma.pdf
JUST DO QUESTION 32) You have discussed with the human resource ma.pdf
Dhanrajsolanki2091
 
Ins struction Use the information that is associated with your name .pdf
Ins struction Use the information that is associated with your name .pdfIns struction Use the information that is associated with your name .pdf
Ins struction Use the information that is associated with your name .pdf
Dhanrajsolanki2091
 
I how does double fertilization aid in the survival of land plants o.pdf
I how does double fertilization aid in the survival of land plants o.pdfI how does double fertilization aid in the survival of land plants o.pdf
I how does double fertilization aid in the survival of land plants o.pdf
Dhanrajsolanki2091
 
how does malpractice affect quality of healthcare service What are .pdf
how does malpractice affect quality of healthcare service What are .pdfhow does malpractice affect quality of healthcare service What are .pdf
how does malpractice affect quality of healthcare service What are .pdf
Dhanrajsolanki2091
 
How can critical researchers claim to represent groups to which they.pdf
How can critical researchers claim to represent groups to which they.pdfHow can critical researchers claim to represent groups to which they.pdf
How can critical researchers claim to represent groups to which they.pdf
Dhanrajsolanki2091
 
Discuss Allport’s concept of psychological healthy personality.Des.pdf
Discuss Allport’s concept of psychological healthy personality.Des.pdfDiscuss Allport’s concept of psychological healthy personality.Des.pdf
Discuss Allport’s concept of psychological healthy personality.Des.pdf
Dhanrajsolanki2091
 
Earning revenue journal entry is recorded asA Increases assets.pdf
Earning revenue journal entry is recorded asA Increases assets.pdfEarning revenue journal entry is recorded asA Increases assets.pdf
Earning revenue journal entry is recorded asA Increases assets.pdf
Dhanrajsolanki2091
 
Discuss why is it important to use logical and physical data flow di.pdf
Discuss why is it important to use logical and physical data flow di.pdfDiscuss why is it important to use logical and physical data flow di.pdf
Discuss why is it important to use logical and physical data flow di.pdf
Dhanrajsolanki2091
 
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdf
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdfDid HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdf
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdf
Dhanrajsolanki2091
 
Define each of the following terms. Be clear whether it is at develop.pdf
Define each of the following terms. Be clear whether it is at develop.pdfDefine each of the following terms. Be clear whether it is at develop.pdf
Define each of the following terms. Be clear whether it is at develop.pdf
Dhanrajsolanki2091
 
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdf
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdfCould anyone please explain how CPS1 and CPS2 are used for reliabili.pdf
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdf
Dhanrajsolanki2091
 
Complete the following code by deallocating the memory. Int ptr1; .pdf
Complete the following code by deallocating the memory.  Int ptr1;  .pdfComplete the following code by deallocating the memory.  Int ptr1;  .pdf
Complete the following code by deallocating the memory. Int ptr1; .pdf
Dhanrajsolanki2091
 

More from Dhanrajsolanki2091 (20)

Please I need help with this....Please also provide comments in each.pdf
Please I need help with this....Please also provide comments in each.pdfPlease I need help with this....Please also provide comments in each.pdf
Please I need help with this....Please also provide comments in each.pdf
 
Please give me the origin and history on Hassall’s corpusclesSol.pdf
Please give me the origin and history on Hassall’s corpusclesSol.pdfPlease give me the origin and history on Hassall’s corpusclesSol.pdf
Please give me the origin and history on Hassall’s corpusclesSol.pdf
 
OBJ. 2 PE 12-2A Dividing partnership net income Han Lee and Monica An.pdf
OBJ. 2 PE 12-2A Dividing partnership net income Han Lee and Monica An.pdfOBJ. 2 PE 12-2A Dividing partnership net income Han Lee and Monica An.pdf
OBJ. 2 PE 12-2A Dividing partnership net income Han Lee and Monica An.pdf
 
O’Connor says that Aristotelian justice “overcomes misorientation to.pdf
O’Connor says that Aristotelian justice “overcomes misorientation to.pdfO’Connor says that Aristotelian justice “overcomes misorientation to.pdf
O’Connor says that Aristotelian justice “overcomes misorientation to.pdf
 
Let T R^5 rightarrow R^3 be a linear transformation whose null space.pdf
Let T R^5 rightarrow R^3 be a linear transformation whose null space.pdfLet T R^5 rightarrow R^3 be a linear transformation whose null space.pdf
Let T R^5 rightarrow R^3 be a linear transformation whose null space.pdf
 
Make drawings of both organisms stained in each staining procedure. L.pdf
Make drawings of both organisms stained in each staining procedure. L.pdfMake drawings of both organisms stained in each staining procedure. L.pdf
Make drawings of both organisms stained in each staining procedure. L.pdf
 
Link to TextThese selected condensed data are taken from a recent ba.pdf
Link to TextThese selected condensed data are taken from a recent ba.pdfLink to TextThese selected condensed data are taken from a recent ba.pdf
Link to TextThese selected condensed data are taken from a recent ba.pdf
 
Java Database Connect Write a program that views, inserts, and u.pdf
Java Database Connect Write a program that views, inserts, and u.pdfJava Database Connect Write a program that views, inserts, and u.pdf
Java Database Connect Write a program that views, inserts, and u.pdf
 
JUST DO QUESTION 32) You have discussed with the human resource ma.pdf
JUST DO QUESTION 32) You have discussed with the human resource ma.pdfJUST DO QUESTION 32) You have discussed with the human resource ma.pdf
JUST DO QUESTION 32) You have discussed with the human resource ma.pdf
 
Ins struction Use the information that is associated with your name .pdf
Ins struction Use the information that is associated with your name .pdfIns struction Use the information that is associated with your name .pdf
Ins struction Use the information that is associated with your name .pdf
 
I how does double fertilization aid in the survival of land plants o.pdf
I how does double fertilization aid in the survival of land plants o.pdfI how does double fertilization aid in the survival of land plants o.pdf
I how does double fertilization aid in the survival of land plants o.pdf
 
how does malpractice affect quality of healthcare service What are .pdf
how does malpractice affect quality of healthcare service What are .pdfhow does malpractice affect quality of healthcare service What are .pdf
how does malpractice affect quality of healthcare service What are .pdf
 
How can critical researchers claim to represent groups to which they.pdf
How can critical researchers claim to represent groups to which they.pdfHow can critical researchers claim to represent groups to which they.pdf
How can critical researchers claim to represent groups to which they.pdf
 
Discuss Allport’s concept of psychological healthy personality.Des.pdf
Discuss Allport’s concept of psychological healthy personality.Des.pdfDiscuss Allport’s concept of psychological healthy personality.Des.pdf
Discuss Allport’s concept of psychological healthy personality.Des.pdf
 
Earning revenue journal entry is recorded asA Increases assets.pdf
Earning revenue journal entry is recorded asA Increases assets.pdfEarning revenue journal entry is recorded asA Increases assets.pdf
Earning revenue journal entry is recorded asA Increases assets.pdf
 
Discuss why is it important to use logical and physical data flow di.pdf
Discuss why is it important to use logical and physical data flow di.pdfDiscuss why is it important to use logical and physical data flow di.pdf
Discuss why is it important to use logical and physical data flow di.pdf
 
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdf
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdfDid HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdf
Did HBGary’s Aaron Barr have the legal and ethical right to pursue A.pdf
 
Define each of the following terms. Be clear whether it is at develop.pdf
Define each of the following terms. Be clear whether it is at develop.pdfDefine each of the following terms. Be clear whether it is at develop.pdf
Define each of the following terms. Be clear whether it is at develop.pdf
 
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdf
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdfCould anyone please explain how CPS1 and CPS2 are used for reliabili.pdf
Could anyone please explain how CPS1 and CPS2 are used for reliabili.pdf
 
Complete the following code by deallocating the memory. Int ptr1; .pdf
Complete the following code by deallocating the memory.  Int ptr1;  .pdfComplete the following code by deallocating the memory.  Int ptr1;  .pdf
Complete the following code by deallocating the memory. Int ptr1; .pdf
 

Recently uploaded

Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 

Recently uploaded (20)

Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 

Write a static method named numberoddSum that accepts a positive inte.pdf

  • 1. Write a static method named numberoddSum that accepts a positive integer returns the sum of its odd digits. For example, the call numberOddSum (1436527) should return 16. Solution Hi, PLease find my implementtion. Please let me know in case of any issue. import java.util.Scanner; public class OddDigitsSum { public static int numberOddSum(int n){ int sum = 0; // variable to store sum of odd digits // if n is negative, making it positive if(n < 0) n = -n; while( n > 0){ int digit = n%10; // getting current digit if(digit % 2 == 1) sum = sum + digit; n = n/10; } return sum; } public static void main(String[] args) { Scanner sc = new Scanner(System.in);
  • 2. System.out.print("Enter a integer: "); int number = sc.nextInt(); System.out.println("Odd digit sum: "+numberOddSum(number)); } } /* Sample run: Enter a integer: 4321234 Odd digit sum: 7 */