SlideShare una empresa de Scribd logo
1 de 2
1. The following given statements:
import java.io.*;
import java.util.*;
2. The following given main() method:
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter an integer value: ");
long number = input.nextLong();
System.out.println("The number of odd digits in the number is " + countOdd(number));
}
3. A recursive method countOdd that will compute the number of odd digits in a number. The
method must handle inputs of both positive and negative numbers.
Solution
import java.util.Scanner;
public class Recursive {
public static int countOdd( long num){
int cnt = 0;
if (num == 0)
return 0;
long rem = num % 10;
cnt = countOdd (num/10);
if ((rem % 2) != 0)
cnt += 1;
return cnt;
}
public static void main(String[] args){
Scanner input = new Scanner(System. in );
System. out .println("Enter an integer value: ");
long number = input.nextLong();
System. out .println("The number of odd digits in the number is " + countOdd (number));
}
}

Más contenido relacionado

Similar a 1- The following given statements- import java-io--- import java-util.docx

import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
optokunal1
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdf
angelsfashion1
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
Aiman Hud
 
import java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdfimport java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdf
anithareadymade
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
Katecate1
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
MaruMengesha
 

Similar a 1- The following given statements- import java-io--- import java-util.docx (15)

Codeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdfCodeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdf
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
C# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdfC# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdf
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdf
 
LAB1.docx
LAB1.docxLAB1.docx
LAB1.docx
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
 
import java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdfimport java.util.; public class DecimalToBinary { public stat.pdf
import java.util.; public class DecimalToBinary { public stat.pdf
 
Java programs
Java programsJava programs
Java programs
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
 
An input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docxAn input file A1-txt is given which contains a list of integer values-.docx
An input file A1-txt is given which contains a list of integer values-.docx
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
 

Más de tjames442

1- What kind of contract did Lulene and Ellen have- What kinds of issu.docx
1- What kind of contract did Lulene and Ellen have- What kinds of issu.docx1- What kind of contract did Lulene and Ellen have- What kinds of issu.docx
1- What kind of contract did Lulene and Ellen have- What kinds of issu.docx
tjames442
 
1- What is a database- Give some examples- 2- What is a database manag.docx
1- What is a database- Give some examples- 2- What is a database manag.docx1- What is a database- Give some examples- 2- What is a database manag.docx
1- What is a database- Give some examples- 2- What is a database manag.docx
tjames442
 
1- What are phonons- What information can be obtained by studying the.docx
1- What are phonons- What information can be obtained by studying the.docx1- What are phonons- What information can be obtained by studying the.docx
1- What are phonons- What information can be obtained by studying the.docx
tjames442
 
1- Single convex lenses can be used to make images of far away objects.docx
1- Single convex lenses can be used to make images of far away objects.docx1- Single convex lenses can be used to make images of far away objects.docx
1- Single convex lenses can be used to make images of far away objects.docx
tjames442
 

Más de tjames442 (20)

A star is 17-2 ly (light-years) from Earth- HINT (a) At what constant.docx
A star is 17-2 ly (light-years) from Earth- HINT (a) At what constant.docxA star is 17-2 ly (light-years) from Earth- HINT (a) At what constant.docx
A star is 17-2 ly (light-years) from Earth- HINT (a) At what constant.docx
 
A true statement about atoms is that they can emit radiation at freque.docx
A true statement about atoms is that they can emit radiation at freque.docxA true statement about atoms is that they can emit radiation at freque.docx
A true statement about atoms is that they can emit radiation at freque.docx
 
A TDR price of a length of 60 centimeters was installed vertically int.docx
A TDR price of a length of 60 centimeters was installed vertically int.docxA TDR price of a length of 60 centimeters was installed vertically int.docx
A TDR price of a length of 60 centimeters was installed vertically int.docx
 
1- The real interest rate is defined as- A- inflation minus the nomina.docx
1- The real interest rate is defined as- A- inflation minus the nomina.docx1- The real interest rate is defined as- A- inflation minus the nomina.docx
1- The real interest rate is defined as- A- inflation minus the nomina.docx
 
1- The intNumbers array is a one dimensional array- Write the statemen.docx
1- The intNumbers array is a one dimensional array- Write the statemen.docx1- The intNumbers array is a one dimensional array- Write the statemen.docx
1- The intNumbers array is a one dimensional array- Write the statemen.docx
 
1- The following data were reported by a corporation- Authorized share.docx
1- The following data were reported by a corporation- Authorized share.docx1- The following data were reported by a corporation- Authorized share.docx
1- The following data were reported by a corporation- Authorized share.docx
 
1- The following change is physical or chemical- Explain why- Water bo.docx
1- The following change is physical or chemical- Explain why- Water bo.docx1- The following change is physical or chemical- Explain why- Water bo.docx
1- The following change is physical or chemical- Explain why- Water bo.docx
 
1- Which of the following is a situation in which an involuntary trans.docx
1- Which of the following is a situation in which an involuntary trans.docx1- Which of the following is a situation in which an involuntary trans.docx
1- Which of the following is a situation in which an involuntary trans.docx
 
1- Which of the following is NOT a function of a firewall- a- Blocks o.docx
1- Which of the following is NOT a function of a firewall- a- Blocks o.docx1- Which of the following is NOT a function of a firewall- a- Blocks o.docx
1- Which of the following is NOT a function of a firewall- a- Blocks o.docx
 
1- What soil characteristics influence compressibility 2- Why is conso.docx
1- What soil characteristics influence compressibility 2- Why is conso.docx1- What soil characteristics influence compressibility 2- Why is conso.docx
1- What soil characteristics influence compressibility 2- Why is conso.docx
 
1- What type of encryption does PKI use- Symmetric Asymmetric DES AES.docx
1- What type of encryption does PKI use- Symmetric Asymmetric DES AES.docx1- What type of encryption does PKI use- Symmetric Asymmetric DES AES.docx
1- What type of encryption does PKI use- Symmetric Asymmetric DES AES.docx
 
1- What kind of contract did Lulene and Ellen have- What kinds of issu.docx
1- What kind of contract did Lulene and Ellen have- What kinds of issu.docx1- What kind of contract did Lulene and Ellen have- What kinds of issu.docx
1- What kind of contract did Lulene and Ellen have- What kinds of issu.docx
 
1- what is the net ionic equation for the neutralization of HBr with K.docx
1- what is the net ionic equation for the neutralization of HBr with K.docx1- what is the net ionic equation for the neutralization of HBr with K.docx
1- what is the net ionic equation for the neutralization of HBr with K.docx
 
1- What is outsourcing- What are advantages and disadvantages of outso.docx
1- What is outsourcing- What are advantages and disadvantages of outso.docx1- What is outsourcing- What are advantages and disadvantages of outso.docx
1- What is outsourcing- What are advantages and disadvantages of outso.docx
 
1- What is the difference between OSI and TCP-IP layered models-Soluti.docx
1- What is the difference between OSI and TCP-IP layered models-Soluti.docx1- What is the difference between OSI and TCP-IP layered models-Soluti.docx
1- What is the difference between OSI and TCP-IP layered models-Soluti.docx
 
1- What is a database- Give some examples- 2- What is a database manag.docx
1- What is a database- Give some examples- 2- What is a database manag.docx1- What is a database- Give some examples- 2- What is a database manag.docx
1- What is a database- Give some examples- 2- What is a database manag.docx
 
1- What are the functional sources of power- 2- Distinguish between pe.docx
1- What are the functional sources of power- 2- Distinguish between pe.docx1- What are the functional sources of power- 2- Distinguish between pe.docx
1- What are the functional sources of power- 2- Distinguish between pe.docx
 
1- What are phonons- What information can be obtained by studying the.docx
1- What are phonons- What information can be obtained by studying the.docx1- What are phonons- What information can be obtained by studying the.docx
1- What are phonons- What information can be obtained by studying the.docx
 
1- void fun(int &j) { j++- } int main() { int i - 20- fun(i)- printf(-.docx
1- void fun(int &j) { j++- } int main() { int i - 20- fun(i)- printf(-.docx1- void fun(int &j) { j++- } int main() { int i - 20- fun(i)- printf(-.docx
1- void fun(int &j) { j++- } int main() { int i - 20- fun(i)- printf(-.docx
 
1- Single convex lenses can be used to make images of far away objects.docx
1- Single convex lenses can be used to make images of far away objects.docx1- Single convex lenses can be used to make images of far away objects.docx
1- Single convex lenses can be used to make images of far away objects.docx
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Último (20)

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 

1- The following given statements- import java-io--- import java-util.docx

  • 1. 1. The following given statements: import java.io.*; import java.util.*; 2. The following given main() method: public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter an integer value: "); long number = input.nextLong(); System.out.println("The number of odd digits in the number is " + countOdd(number)); } 3. A recursive method countOdd that will compute the number of odd digits in a number. The method must handle inputs of both positive and negative numbers. Solution import java.util.Scanner; public class Recursive { public static int countOdd( long num){ int cnt = 0; if (num == 0) return 0; long rem = num % 10;
  • 2. cnt = countOdd (num/10); if ((rem % 2) != 0) cnt += 1; return cnt; } public static void main(String[] args){ Scanner input = new Scanner(System. in ); System. out .println("Enter an integer value: "); long number = input.nextLong(); System. out .println("The number of odd digits in the number is " + countOdd (number)); } }