జావాలో రెండు సంఖ్యల min()ని ఎలా కనుగొనాలి?
జావా విస్తృతమైన సులభ కార్యకలాపాల కోసం " java.lang.Math " అని పిలువబడే సిస్టమ్ లైబ్రరీని అందిస్తుంది . త్రికోణమితి నుండి లాగరిథమిక్ ఫంక్షన్ల వరకు, మీరు ఈ లైబ్రరీ యొక్క విభిన్న కార్యాచరణల కారణంగా అందించిన పద్ధతులను ఉపయోగించి సంఖ్య యొక్క కనిష్ట/గరిష్ట లేదా సంపూర్ణ సంఖ్యను కనుగొనవచ్చు.Math.min() పద్ధతి
పద్ధతి యొక్క సాధారణ ప్రాతినిధ్యం ఇక్కడ ఉంది.
Math.min(a, b)
ఈ ఫంక్షన్ ఒకే రకమైన int , long , float లేదా డబుల్ రెండు పారామితులను అంగీకరిస్తుందని దయచేసి గమనించండి . దాని యొక్క సమర్థవంతమైన ఉపయోగాన్ని అర్థం చేసుకోవడానికి Math.min() పద్ధతి యొక్క ఎక్జిక్యూటబుల్ ఉదాహరణను చూద్దాం . అవుట్పుట్లను ధృవీకరించడానికి మీరు మీ IDEలో స్క్రిప్ట్ని అమలు చేశారని నిర్ధారించుకోండి.
ఉదాహరణ 1
package com.math.min.core
public class MathMinMethod {
public static void main(String[] args) {
int leenasAge = 10;
int tiffanysAge = 15;
// example of min () function
int min = Math.min(leenasAge, tiffanysAge);
System.out.print("Who's the younger sister? ");
if (min < tiffanysAge)
System.out.print("Leena ------- Age " + leenasAge);
else
System.out.print("Tiffany ------- Age " + tiffanysAge);
}
}
అవుట్పుట్
చెల్లెలు ఎవరు? లీనా ------- వయస్సు 10
వివరణ
లైన్ 8 వద్ద, int min = Math.min(leenasAge, tiffanysAge); int min min() ఫంక్షన్ ద్వారా అందించబడిన కనీస సంఖ్యను నిల్వ చేస్తుంది . తర్వాత మేము చిన్న తోబుట్టువుల వయస్సును కనుగొనడానికి ఆ ఫలితాన్ని ఉపయోగిస్తాము.ఉదాహరణ 2
package com.math.min.core;
public class MathMinMethod {
public static void main(String[] args) {
double berriesSoldInKg = 15.6;
double cherriesSoldInKg = 21.3;
// example of min () function
double min = Math.min(berriesSoldInKg, cherriesSoldInKg);
System.out.println("What's the minimum weight sold?");
if (min != cherriesSoldInKg)
System.out.print("Berries: " + berriesSoldInKg + " kg");
else
System.out.print("Cherries: " + cherriesSoldInKg +"kg");
}
}
అవుట్పుట్
విక్రయించిన కనీస బరువు ఎంత? బెర్రీలు: 15.6 కిలోలు
GO TO FULL VERSION