SlideShare a Scribd company logo
1 of 9
Java Numbers Class
•What is a Number class?
•What is wrapper class?
•What are the methods in wrapper class.
4/10/2019 1Jamsher Bhanbhro(F16CS11)
Number class
• Using objects instead of primitive data types is known
as wrapper class.
• Converting Primitive data type to object data is known
as Boxing.
• There are six wrapper classes which are (int, byte, float,
short, long, double).
• These wrapper classes are subclasses of an abstract
class Number.
• Boxing is very important to use so it will be done by
using compilers.
• We have to pass value of the parameters to the
constructor of wrapper class.
4/10/2019 Jamsher Bhanbhro(F16CS11) 2
How to do Boxing and UnBoxing
public class Boxex{
public static void main(String args[]){
Integer x=11;
// here the value of x is boxed in Integer object
x = x+1;
// here the value of x is unboxed
System.out.println(“”);
}
}
4/10/2019 Jamsher Bhanbhro(F16CS11) 3
dTValue()
• This method is used convert the value of Number
Object to the primitive data type.
• These are intValue(), shortValue(),
longValue(),floatValue, doubleValue(),byteValue()
Integer a=11;
S.O.P(a.byteValue());
S.O.P(a.intValue());
S.O.P(a.doubleValue());
etc
4/10/2019 Jamsher Bhanbhro(F16CS11) 4
compareTo and equals method
• compareTo this method used to compare the object value with given
parameters of method
int a=11; SOP(a.compareTo(12));
• If the integer arg is equal to object return 0.
• If greater than return 1.
• If less than return -1.
• The equals() method determines whether the Number object that
invokes the method is equal to the object that is passed as an
argument.
Integer x=10;
Integer y=15;
SOP(x.equals(y));
• If equals than answer will be true otherwise answer will be false.
4/10/2019 Jamsher Bhanbhro(F16CS11) 5
valueOf(dt obj)
• The valueOf method returns the relevant
Number Object holding the value of the
argument passed. The argument can be a
primitive data type, String, etc
• This method is a static method. The method
can take two arguments, where one is a String
and the other is a radix.
• valueOf(int i), valueOf(String s),
valueOf(String s, int radix)
4/10/2019 Jamsher Bhanbhro(F16CS11) 6
Other Methods
• parseInt() :This method is used to get the primitive data type of a certain
String. parseXxx() is a static method and can have one argument or two.
• abs() Method : float abs(float f)
• ceil() :double ceil(double d):The method ceil gives the smallest integer that
is greater than or equal to the argument.
• floor(): The method floor gives the largest integer that is less than or equal
to the argument.
• double floor(double d), double floor(float f)
• rint(): The method rint returns the integer that is closest in value to the
argument. double rint(double d)
• round(): The method round returns the closest long or int, as given by the
methods return type. long round(double d)
• exp(): The method returns the base of the natural logarithms, e, to the
power of the argument. double exp(double d)
4/10/2019 Jamsher Bhanbhro(F16CS11) 7
Methods
• log(): The method returns the natural logarithm of the argument.
double log(double d)
• pow() : The method returns the value of the first argument raised to
the power of the second argument. double pow(double base, double
exponent)
• sqrt() : The method returns the square root of the argument.
for example: double sqrt(double d).
• sin(), cos() , tan() syntax: double tan(double d)
• asin() , acos() , atan() syntax: double atan(double d)
• toDegrees() : The method converts the argument value to degrees.
double toDegrees(double d)
• toRadians():
4/10/2019 Jamsher Bhanbhro(F16CS11) 8
Tasks
• Use all above number class methods in your
program.
• Make a scientific calculator
4/10/2019 Jamsher Bhanbhro(F16CS11) 9

More Related Content

What's hot

Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using javaNarayan Sau
 
TRIES_data_structure
TRIES_data_structureTRIES_data_structure
TRIES_data_structureddewithaman10
 
Data Handling and Function
Data Handling and FunctionData Handling and Function
Data Handling and FunctionRatnaJava
 
Arrays accessing using for loops
Arrays accessing using for loopsArrays accessing using for loops
Arrays accessing using for loopssangrampatil81
 
Applications of data structures
Applications of data structuresApplications of data structures
Applications of data structuresWipro
 
Dynamic memory allocation and linked lists
Dynamic memory allocation and linked listsDynamic memory allocation and linked lists
Dynamic memory allocation and linked listsDeepam Aggarwal
 
Pointer to array and structure
Pointer to array and structurePointer to array and structure
Pointer to array and structuresangrampatil81
 
1.5.ensemble learning with apache spark m llib 1.5
1.5.ensemble learning with apache spark m llib 1.51.5.ensemble learning with apache spark m llib 1.5
1.5.ensemble learning with apache spark m llib 1.5leorick lin
 
Cso gaddis java_chapter6
Cso gaddis java_chapter6Cso gaddis java_chapter6
Cso gaddis java_chapter6RhettB
 
NaBL: A Meta-Language for Declarative Name Binding and Scope Rules
NaBL: A Meta-Language for Declarative Name Binding  and Scope RulesNaBL: A Meta-Language for Declarative Name Binding  and Scope Rules
NaBL: A Meta-Language for Declarative Name Binding and Scope RulesEelco Visser
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2ndConnex
 
Object oriented programming 2 elements of programming
Object oriented programming 2 elements of programmingObject oriented programming 2 elements of programming
Object oriented programming 2 elements of programmingVaibhav Khanna
 
Python data type
Python data typePython data type
Python data typenuripatidar
 

What's hot (20)

Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using java
 
TRIES_data_structure
TRIES_data_structureTRIES_data_structure
TRIES_data_structure
 
Data Handling and Function
Data Handling and FunctionData Handling and Function
Data Handling and Function
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Java -lec-6
Java -lec-6Java -lec-6
Java -lec-6
 
Arrays accessing using for loops
Arrays accessing using for loopsArrays accessing using for loops
Arrays accessing using for loops
 
C++ version 1
C++  version 1C++  version 1
C++ version 1
 
C++ Version 2
C++  Version 2C++  Version 2
C++ Version 2
 
Applications of data structures
Applications of data structuresApplications of data structures
Applications of data structures
 
Dynamic memory allocation and linked lists
Dynamic memory allocation and linked listsDynamic memory allocation and linked lists
Dynamic memory allocation and linked lists
 
Pointer to array and structure
Pointer to array and structurePointer to array and structure
Pointer to array and structure
 
1.5.ensemble learning with apache spark m llib 1.5
1.5.ensemble learning with apache spark m llib 1.51.5.ensemble learning with apache spark m llib 1.5
1.5.ensemble learning with apache spark m llib 1.5
 
Cso gaddis java_chapter6
Cso gaddis java_chapter6Cso gaddis java_chapter6
Cso gaddis java_chapter6
 
NaBL: A Meta-Language for Declarative Name Binding and Scope Rules
NaBL: A Meta-Language for Declarative Name Binding  and Scope RulesNaBL: A Meta-Language for Declarative Name Binding  and Scope Rules
NaBL: A Meta-Language for Declarative Name Binding and Scope Rules
 
Array in c
Array in cArray in c
Array in c
 
Basics of oops concept
Basics of oops conceptBasics of oops concept
Basics of oops concept
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
Object oriented programming 2 elements of programming
Object oriented programming 2 elements of programmingObject oriented programming 2 elements of programming
Object oriented programming 2 elements of programming
 
Scala style-guide
Scala style-guideScala style-guide
Scala style-guide
 
Python data type
Python data typePython data type
Python data type
 

Similar to Lect9

Similar to Lect9 (20)

Lect10
Lect10Lect10
Lect10
 
DAY_1.3.pptx
DAY_1.3.pptxDAY_1.3.pptx
DAY_1.3.pptx
 
Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)Strings In OOP(Object oriented programming)
Strings In OOP(Object oriented programming)
 
Core java
Core javaCore java
Core java
 
Lec2-Array.pptx
Lec2-Array.pptxLec2-Array.pptx
Lec2-Array.pptx
 
L9 wrapper classes
L9 wrapper classesL9 wrapper classes
L9 wrapper classes
 
Lecture 3.pptx
Lecture 3.pptxLecture 3.pptx
Lecture 3.pptx
 
Java Day-4
Java Day-4Java Day-4
Java Day-4
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
 
PPT on Python - illustrating Python for BBA, B.Tech
PPT on Python - illustrating Python for BBA, B.TechPPT on Python - illustrating Python for BBA, B.Tech
PPT on Python - illustrating Python for BBA, B.Tech
 
Java tutorial part 3
Java tutorial part 3Java tutorial part 3
Java tutorial part 3
 
Java Concepts
Java ConceptsJava Concepts
Java Concepts
 
Python Strings Methods
Python Strings MethodsPython Strings Methods
Python Strings Methods
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
 
Dynamic Memory Allocation.pptx
Dynamic Memory Allocation.pptxDynamic Memory Allocation.pptx
Dynamic Memory Allocation.pptx
 
Acm aleppo cpc training ninth session
Acm aleppo cpc training ninth sessionAcm aleppo cpc training ninth session
Acm aleppo cpc training ninth session
 
Refactoring bad codesmell
Refactoring bad codesmellRefactoring bad codesmell
Refactoring bad codesmell
 

More from Jamsher bhanbhro

Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and InterfacesJamsher bhanbhro
 
Method, Constructor, Method Overloading, Method Overriding, Inheritance In Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In  JavaMethod, Constructor, Method Overloading, Method Overriding, Inheritance In  Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In JavaJamsher bhanbhro
 
Regular Expressions in Java.
Regular Expressions in Java.Regular Expressions in Java.
Regular Expressions in Java.Jamsher bhanbhro
 
Java Arrays and DateTime Functions
Java Arrays and DateTime FunctionsJava Arrays and DateTime Functions
Java Arrays and DateTime FunctionsJamsher bhanbhro
 
Compiling and understanding first program in java
Compiling and understanding first program in javaCompiling and understanding first program in java
Compiling and understanding first program in javaJamsher bhanbhro
 
Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)Jamsher bhanbhro
 

More from Jamsher bhanbhro (13)

Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and Interfaces
 
Method, Constructor, Method Overloading, Method Overriding, Inheritance In Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In  JavaMethod, Constructor, Method Overloading, Method Overriding, Inheritance In  Java
Method, Constructor, Method Overloading, Method Overriding, Inheritance In Java
 
Regular Expressions in Java.
Regular Expressions in Java.Regular Expressions in Java.
Regular Expressions in Java.
 
Java Arrays and DateTime Functions
Java Arrays and DateTime FunctionsJava Arrays and DateTime Functions
Java Arrays and DateTime Functions
 
Lect8
Lect8Lect8
Lect8
 
Lect7
Lect7Lect7
Lect7
 
Lect6
Lect6Lect6
Lect6
 
Lect5
Lect5Lect5
Lect5
 
Lect4
Lect4Lect4
Lect4
 
Compiling and understanding first program in java
Compiling and understanding first program in javaCompiling and understanding first program in java
Compiling and understanding first program in java
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Caap presentation by me
Caap presentation by meCaap presentation by me
Caap presentation by me
 
Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)Introduction to parts of Computer(Computer Fundamentals)
Introduction to parts of Computer(Computer Fundamentals)
 

Recently uploaded

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

Lect9

  • 1. Java Numbers Class •What is a Number class? •What is wrapper class? •What are the methods in wrapper class. 4/10/2019 1Jamsher Bhanbhro(F16CS11)
  • 2. Number class • Using objects instead of primitive data types is known as wrapper class. • Converting Primitive data type to object data is known as Boxing. • There are six wrapper classes which are (int, byte, float, short, long, double). • These wrapper classes are subclasses of an abstract class Number. • Boxing is very important to use so it will be done by using compilers. • We have to pass value of the parameters to the constructor of wrapper class. 4/10/2019 Jamsher Bhanbhro(F16CS11) 2
  • 3. How to do Boxing and UnBoxing public class Boxex{ public static void main(String args[]){ Integer x=11; // here the value of x is boxed in Integer object x = x+1; // here the value of x is unboxed System.out.println(“”); } } 4/10/2019 Jamsher Bhanbhro(F16CS11) 3
  • 4. dTValue() • This method is used convert the value of Number Object to the primitive data type. • These are intValue(), shortValue(), longValue(),floatValue, doubleValue(),byteValue() Integer a=11; S.O.P(a.byteValue()); S.O.P(a.intValue()); S.O.P(a.doubleValue()); etc 4/10/2019 Jamsher Bhanbhro(F16CS11) 4
  • 5. compareTo and equals method • compareTo this method used to compare the object value with given parameters of method int a=11; SOP(a.compareTo(12)); • If the integer arg is equal to object return 0. • If greater than return 1. • If less than return -1. • The equals() method determines whether the Number object that invokes the method is equal to the object that is passed as an argument. Integer x=10; Integer y=15; SOP(x.equals(y)); • If equals than answer will be true otherwise answer will be false. 4/10/2019 Jamsher Bhanbhro(F16CS11) 5
  • 6. valueOf(dt obj) • The valueOf method returns the relevant Number Object holding the value of the argument passed. The argument can be a primitive data type, String, etc • This method is a static method. The method can take two arguments, where one is a String and the other is a radix. • valueOf(int i), valueOf(String s), valueOf(String s, int radix) 4/10/2019 Jamsher Bhanbhro(F16CS11) 6
  • 7. Other Methods • parseInt() :This method is used to get the primitive data type of a certain String. parseXxx() is a static method and can have one argument or two. • abs() Method : float abs(float f) • ceil() :double ceil(double d):The method ceil gives the smallest integer that is greater than or equal to the argument. • floor(): The method floor gives the largest integer that is less than or equal to the argument. • double floor(double d), double floor(float f) • rint(): The method rint returns the integer that is closest in value to the argument. double rint(double d) • round(): The method round returns the closest long or int, as given by the methods return type. long round(double d) • exp(): The method returns the base of the natural logarithms, e, to the power of the argument. double exp(double d) 4/10/2019 Jamsher Bhanbhro(F16CS11) 7
  • 8. Methods • log(): The method returns the natural logarithm of the argument. double log(double d) • pow() : The method returns the value of the first argument raised to the power of the second argument. double pow(double base, double exponent) • sqrt() : The method returns the square root of the argument. for example: double sqrt(double d). • sin(), cos() , tan() syntax: double tan(double d) • asin() , acos() , atan() syntax: double atan(double d) • toDegrees() : The method converts the argument value to degrees. double toDegrees(double d) • toRadians(): 4/10/2019 Jamsher Bhanbhro(F16CS11) 8
  • 9. Tasks • Use all above number class methods in your program. • Make a scientific calculator 4/10/2019 Jamsher Bhanbhro(F16CS11) 9