SlideShare a Scribd company logo
1 of 2
Object oriented programming question.
Using only conditionals and relational operators, write the method smallest Positive that takes
two numbers and returns the smallest positive one. If neither argument is positive, it returns 0.
For example, smallest Positive (7, 4) and smallest Positive (4, 7) both return 4, smallest Positive
(7, -4) and smallest Positive (-4, 7) both return 7, and smallest Positive (-7, -4) returns 0. public
int smallest Positive (int x, int y) should return the smallest positive of x and y or 0 for two non-
positive arguments.
Solution
Test1.java
import java.util.Scanner;
public class Test1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.println("Enter first value :");
int x = scan.nextInt();
System.out.println("Enter second value :");
int y = scan.nextInt();
int smallValue = smallestPositive(x,y);
System.out.println("The Small value is "+smallValue);
}
public static int smallestPositive(int x, int y){
if(x < 0 && y < 0)
return 0;
else if(x < y)
return x;
else
return y;
}
}
Output:
Enter first value :
-7
Enter second value :
-4
The Small value is 0
Enter first value :
7
Enter second value :
-1
The Small value is -1

More Related Content

Similar to Object oriented programming question- Using only conditionals and rela.docx

MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfanjanacottonmills
 
Factors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdfFactors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdfdeepakangel
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lecturesMSohaib24
 
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.pdfanurag1231
 
2 m2.w2.d1 - oop
2   m2.w2.d1 - oop2   m2.w2.d1 - oop
2 m2.w2.d1 - oopJustin Chen
 

Similar to Object oriented programming question- Using only conditionals and rela.docx (8)

Java final lab
Java final labJava final lab
Java final lab
 
06slide.ppt
06slide.ppt06slide.ppt
06slide.ppt
 
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
 
Factors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdfFactors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdf
 
Java programs
Java programsJava programs
Java programs
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lectures
 
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
 
2 m2.w2.d1 - oop
2   m2.w2.d1 - oop2   m2.w2.d1 - oop
2 m2.w2.d1 - oop
 

More from altonm

Nuclear disarmament should result in the retrieval of large amounts of.docx
Nuclear disarmament should result in the retrieval of large amounts of.docxNuclear disarmament should result in the retrieval of large amounts of.docx
Nuclear disarmament should result in the retrieval of large amounts of.docxaltonm
 
Nomenclature Practice Problems Ch 20 Part I For compounds represented.docx
Nomenclature Practice Problems Ch 20 Part I For compounds represented.docxNomenclature Practice Problems Ch 20 Part I For compounds represented.docx
Nomenclature Practice Problems Ch 20 Part I For compounds represented.docxaltonm
 
NO2 is a yellow gas responsible for the brownish haze that builds up p.docx
NO2 is a yellow gas responsible for the brownish haze that builds up p.docxNO2 is a yellow gas responsible for the brownish haze that builds up p.docx
NO2 is a yellow gas responsible for the brownish haze that builds up p.docxaltonm
 
No need for any sort of explanation- Please only a straightforward ans.docx
No need for any sort of explanation- Please only a straightforward ans.docxNo need for any sort of explanation- Please only a straightforward ans.docx
No need for any sort of explanation- Please only a straightforward ans.docxaltonm
 
No copy and paste from other website- must be in your own words- Thank.docx
No copy and paste from other website- must be in your own words- Thank.docxNo copy and paste from other website- must be in your own words- Thank.docx
No copy and paste from other website- must be in your own words- Thank.docxaltonm
 
nidly s wht is ment the er SolutionThe branch of science and technolog.docx
nidly s wht is ment the er SolutionThe branch of science and technolog.docxnidly s wht is ment the er SolutionThe branch of science and technolog.docx
nidly s wht is ment the er SolutionThe branch of science and technolog.docxaltonm
 
Newton Inc- uses a calendar year for financial reporting- The company (1).docx
Newton Inc- uses a calendar year for financial reporting- The company (1).docxNewton Inc- uses a calendar year for financial reporting- The company (1).docx
Newton Inc- uses a calendar year for financial reporting- The company (1).docxaltonm
 
olecular Forces liquid and sold states- molecules are held together by.docx
olecular Forces liquid and sold states- molecules are held together by.docxolecular Forces liquid and sold states- molecules are held together by.docx
olecular Forces liquid and sold states- molecules are held together by.docxaltonm
 
Okay- so I understand questions 1- however I don-'t get how to find ou.docx
Okay- so I understand questions 1- however I don-'t get how to find ou.docxOkay- so I understand questions 1- however I don-'t get how to find ou.docx
Okay- so I understand questions 1- however I don-'t get how to find ou.docxaltonm
 
ofa fallowing sormally wuma vp faest wee heot in appliod A) water B) w.docx
ofa fallowing sormally wuma vp faest wee heot in appliod A) water B) w.docxofa fallowing sormally wuma vp faest wee heot in appliod A) water B) w.docx
ofa fallowing sormally wuma vp faest wee heot in appliod A) water B) w.docxaltonm
 
Often in science it is helpful to talk about a representative example.docx
Often in science it is helpful to talk about a representative example.docxOften in science it is helpful to talk about a representative example.docx
Often in science it is helpful to talk about a representative example.docxaltonm
 
Obstacles in EHRs Implementation Discuss the major local- national- an.docx
Obstacles in EHRs Implementation Discuss the major local- national- an.docxObstacles in EHRs Implementation Discuss the major local- national- an.docx
Obstacles in EHRs Implementation Discuss the major local- national- an.docxaltonm
 
o be (11) Explain why an object (like a pencil) that is partially subm.docx
o be (11) Explain why an object (like a pencil) that is partially subm.docxo be (11) Explain why an object (like a pencil) that is partially subm.docx
o be (11) Explain why an object (like a pencil) that is partially subm.docxaltonm
 
Numerical Analysis- (Matlab) Write a program that computes an integral.docx
Numerical Analysis- (Matlab) Write a program that computes an integral.docxNumerical Analysis- (Matlab) Write a program that computes an integral.docx
Numerical Analysis- (Matlab) Write a program that computes an integral.docxaltonm
 
Yvon- an accountant- is charged with negligence by Zesty Sauce- Inc--.docx
Yvon- an accountant- is charged with negligence by Zesty Sauce- Inc--.docxYvon- an accountant- is charged with negligence by Zesty Sauce- Inc--.docx
Yvon- an accountant- is charged with negligence by Zesty Sauce- Inc--.docxaltonm
 
Your host has automatically received an IPv6 address working in conjun.docx
Your host has automatically received an IPv6 address working in conjun.docxYour host has automatically received an IPv6 address working in conjun.docx
Your host has automatically received an IPv6 address working in conjun.docxaltonm
 
Your community has decided to construct a hazardous waste facility for.docx
Your community has decided to construct a hazardous waste facility for.docxYour community has decided to construct a hazardous waste facility for.docx
Your community has decided to construct a hazardous waste facility for.docxaltonm
 
Young Corporation incurred research and development costs of $500-000.docx
Young Corporation incurred research and development costs of $500-000.docxYoung Corporation incurred research and development costs of $500-000.docx
Young Corporation incurred research and development costs of $500-000.docxaltonm
 
You work for a small city IT department- and you are reviewing compute.docx
You work for a small city IT department- and you are reviewing compute.docxYou work for a small city IT department- and you are reviewing compute.docx
You work for a small city IT department- and you are reviewing compute.docxaltonm
 
Your CEO is from the old school- What steps would you take to entice h.docx
Your CEO is from the old school- What steps would you take to entice h.docxYour CEO is from the old school- What steps would you take to entice h.docx
Your CEO is from the old school- What steps would you take to entice h.docxaltonm
 

More from altonm (20)

Nuclear disarmament should result in the retrieval of large amounts of.docx
Nuclear disarmament should result in the retrieval of large amounts of.docxNuclear disarmament should result in the retrieval of large amounts of.docx
Nuclear disarmament should result in the retrieval of large amounts of.docx
 
Nomenclature Practice Problems Ch 20 Part I For compounds represented.docx
Nomenclature Practice Problems Ch 20 Part I For compounds represented.docxNomenclature Practice Problems Ch 20 Part I For compounds represented.docx
Nomenclature Practice Problems Ch 20 Part I For compounds represented.docx
 
NO2 is a yellow gas responsible for the brownish haze that builds up p.docx
NO2 is a yellow gas responsible for the brownish haze that builds up p.docxNO2 is a yellow gas responsible for the brownish haze that builds up p.docx
NO2 is a yellow gas responsible for the brownish haze that builds up p.docx
 
No need for any sort of explanation- Please only a straightforward ans.docx
No need for any sort of explanation- Please only a straightforward ans.docxNo need for any sort of explanation- Please only a straightforward ans.docx
No need for any sort of explanation- Please only a straightforward ans.docx
 
No copy and paste from other website- must be in your own words- Thank.docx
No copy and paste from other website- must be in your own words- Thank.docxNo copy and paste from other website- must be in your own words- Thank.docx
No copy and paste from other website- must be in your own words- Thank.docx
 
nidly s wht is ment the er SolutionThe branch of science and technolog.docx
nidly s wht is ment the er SolutionThe branch of science and technolog.docxnidly s wht is ment the er SolutionThe branch of science and technolog.docx
nidly s wht is ment the er SolutionThe branch of science and technolog.docx
 
Newton Inc- uses a calendar year for financial reporting- The company (1).docx
Newton Inc- uses a calendar year for financial reporting- The company (1).docxNewton Inc- uses a calendar year for financial reporting- The company (1).docx
Newton Inc- uses a calendar year for financial reporting- The company (1).docx
 
olecular Forces liquid and sold states- molecules are held together by.docx
olecular Forces liquid and sold states- molecules are held together by.docxolecular Forces liquid and sold states- molecules are held together by.docx
olecular Forces liquid and sold states- molecules are held together by.docx
 
Okay- so I understand questions 1- however I don-'t get how to find ou.docx
Okay- so I understand questions 1- however I don-'t get how to find ou.docxOkay- so I understand questions 1- however I don-'t get how to find ou.docx
Okay- so I understand questions 1- however I don-'t get how to find ou.docx
 
ofa fallowing sormally wuma vp faest wee heot in appliod A) water B) w.docx
ofa fallowing sormally wuma vp faest wee heot in appliod A) water B) w.docxofa fallowing sormally wuma vp faest wee heot in appliod A) water B) w.docx
ofa fallowing sormally wuma vp faest wee heot in appliod A) water B) w.docx
 
Often in science it is helpful to talk about a representative example.docx
Often in science it is helpful to talk about a representative example.docxOften in science it is helpful to talk about a representative example.docx
Often in science it is helpful to talk about a representative example.docx
 
Obstacles in EHRs Implementation Discuss the major local- national- an.docx
Obstacles in EHRs Implementation Discuss the major local- national- an.docxObstacles in EHRs Implementation Discuss the major local- national- an.docx
Obstacles in EHRs Implementation Discuss the major local- national- an.docx
 
o be (11) Explain why an object (like a pencil) that is partially subm.docx
o be (11) Explain why an object (like a pencil) that is partially subm.docxo be (11) Explain why an object (like a pencil) that is partially subm.docx
o be (11) Explain why an object (like a pencil) that is partially subm.docx
 
Numerical Analysis- (Matlab) Write a program that computes an integral.docx
Numerical Analysis- (Matlab) Write a program that computes an integral.docxNumerical Analysis- (Matlab) Write a program that computes an integral.docx
Numerical Analysis- (Matlab) Write a program that computes an integral.docx
 
Yvon- an accountant- is charged with negligence by Zesty Sauce- Inc--.docx
Yvon- an accountant- is charged with negligence by Zesty Sauce- Inc--.docxYvon- an accountant- is charged with negligence by Zesty Sauce- Inc--.docx
Yvon- an accountant- is charged with negligence by Zesty Sauce- Inc--.docx
 
Your host has automatically received an IPv6 address working in conjun.docx
Your host has automatically received an IPv6 address working in conjun.docxYour host has automatically received an IPv6 address working in conjun.docx
Your host has automatically received an IPv6 address working in conjun.docx
 
Your community has decided to construct a hazardous waste facility for.docx
Your community has decided to construct a hazardous waste facility for.docxYour community has decided to construct a hazardous waste facility for.docx
Your community has decided to construct a hazardous waste facility for.docx
 
Young Corporation incurred research and development costs of $500-000.docx
Young Corporation incurred research and development costs of $500-000.docxYoung Corporation incurred research and development costs of $500-000.docx
Young Corporation incurred research and development costs of $500-000.docx
 
You work for a small city IT department- and you are reviewing compute.docx
You work for a small city IT department- and you are reviewing compute.docxYou work for a small city IT department- and you are reviewing compute.docx
You work for a small city IT department- and you are reviewing compute.docx
 
Your CEO is from the old school- What steps would you take to entice h.docx
Your CEO is from the old school- What steps would you take to entice h.docxYour CEO is from the old school- What steps would you take to entice h.docx
Your CEO is from the old school- What steps would you take to entice h.docx
 

Recently uploaded

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
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 Delhikauryashika82
 
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.pdfAdmir Softic
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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)Jisc
 
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 POSCeline George
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
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
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Recently uploaded (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
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
 
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
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.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...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

Object oriented programming question- Using only conditionals and rela.docx

  • 1. Object oriented programming question. Using only conditionals and relational operators, write the method smallest Positive that takes two numbers and returns the smallest positive one. If neither argument is positive, it returns 0. For example, smallest Positive (7, 4) and smallest Positive (4, 7) both return 4, smallest Positive (7, -4) and smallest Positive (-4, 7) both return 7, and smallest Positive (-7, -4) returns 0. public int smallest Positive (int x, int y) should return the smallest positive of x and y or 0 for two non- positive arguments. Solution Test1.java import java.util.Scanner; public class Test1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); System.out.println("Enter first value :"); int x = scan.nextInt(); System.out.println("Enter second value :"); int y = scan.nextInt(); int smallValue = smallestPositive(x,y); System.out.println("The Small value is "+smallValue); } public static int smallestPositive(int x, int y){ if(x < 0 && y < 0) return 0; else if(x < y) return x;
  • 2. else return y; } } Output: Enter first value : -7 Enter second value : -4 The Small value is 0 Enter first value : 7 Enter second value : -1 The Small value is -1