SlideShare a Scribd company logo
1 of 18
Download to read offline
JAVA
"WRITE ONCE, RUN ANYWHERE”
Lec--5
By: Zubair Khalid
Java
£ Java Math Class
£ Java Random Number Class
Java math class contains the following useful methods
Java Math Class
£ Power
£ Absolute
£ Ceil
£ Floor
£ Maximum
£ Minimum
£ Square root
Power
This method is used for calculating power of a number
Math.pow (a, b);
Number
Desired power of that
number
Power (Example)
Import java.Util.Scanner;
Class c1{
Public static void main(string[] args) {
system.Out.Println("please enter A number");
Scanner input=new scanner(system.In);
Int number,power;
Number=input.Nextint();
System.Out.Println("please enter power");
Power=input.Nextint();
System.Out.Println("power of "+number+" is "+math.Pow(number, power));
}
}
Absolute
£ it shows the absolute value of a number.
£ If we enter -ve or +ve value it will show us absolute value.
Math.abs (a);
Number
Absolute (Example)
Import java.Util.*;
Class c2{
Public static void main(string[] args) {
int number;
Scanner scan=new scanner(system.In);
System.Out.Println("please enter A number:");
Number=scan.Nextint();
System.Out.Println(math.Abs(number));
}
}
Ceil
It rounds up the number like if we enter (7.1-7.9) the output always will be 8.0.
Math.ceil (a);
Number
Ceil (Example)
Import java.Util.Scanner;
Class c3{
Public static void main(string[] args) {
double number;
Scanner scan=new scanner(system.In);
System.Out.Println("please enter A number:");
Number=scan.Nextdouble();
System.Out.Println(math.Ceil(number));
Scan.Close();
}
}
Floor
it rounds down the number like if we enter (7.1-7.9) the output always will be 7.0.
Math.floor (a);
Number
Floor (Example)
import java.util.Scanner;
class c4{
public static void main(String[] args) {
double number;
Scanner scan=new Scanner(System.in);
System.out.println("Please Enter A Number:");
number=scan.nextDouble();
System.out.println(Math.floor(number));
scan.close();
}
}
Maximum
it takes two numbers and output the variable which is maximum.
Math.max (a, b);
Number
Maximum (Example)
import java.util.Scanner;
class c5{
public static void main(String[] args) {
double number;
Scanner scan=new Scanner(System.in);
System.out.println("Please Enter A Number:");
number=scan.nextDouble();
System.out.println(Math.max(1.2,5.2));
scan.close();
}
}
Minimum
it takes two numbers and output the variable which is minimum.
Math.min (a, b);
Number
Minimum (Example)
import java.util.Scanner;
class c6{
public static void main(String[] args) {
double number;
Scanner scan=new Scanner(System.in);
System.out.println("Please Enter A Number:");
number=scan.nextDouble();
System.out.println(Math.min(1.2,5.2));
scan.close();
}
}
Square root
it takes a number as input and output the square root of that number.
Math.sqrt (a);
Number
Square root (Example)
import java.util.Scanner;
class c7{
public static void main(String[] args) {
double number;
Scanner scan=new Scanner(System.in);
System.out.println("Please Enter A Number:");
number=scan.nextDouble();
System.out.println(Math.sqrt(number));
scan.close();
}
}
import java.util.Random;
class c8{
public static void main(String[] args) {
Random dice=new Random();
int number;
for(int counter=1;counter<=10;counter++)
{
number=dice.nextInt(6);
System.out.println(number+"");
}
}
}
Java Random Number Class
Example:

More Related Content

What's hot

Formal methods Project Report for the support of slides uploaded
Formal methods Project Report for the support of slides uploaded Formal methods Project Report for the support of slides uploaded
Formal methods Project Report for the support of slides uploaded Shoaib Haseeb
 
Queue implementation
Queue implementationQueue implementation
Queue implementationRajendran
 
The Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterateThe Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iteratePhilip Schwarz
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
 
Chapter iii(advance function)
Chapter iii(advance function)Chapter iii(advance function)
Chapter iii(advance function)Chhom Karath
 
The Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterateThe Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iteratePhilip Schwarz
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]ecko_disasterz
 
Part II: 2-Dimensional Array file name: lab1part2.cpp (10 points) Write a C++...
Part II: 2-Dimensional Array file name: lab1part2.cpp (10 points) Write a C++...Part II: 2-Dimensional Array file name: lab1part2.cpp (10 points) Write a C++...
Part II: 2-Dimensional Array file name: lab1part2.cpp (10 points) Write a C++...hwbloom38
 
BB - Functions (Operations and Piecewise)
BB  - Functions (Operations and Piecewise)BB  - Functions (Operations and Piecewise)
BB - Functions (Operations and Piecewise)JosefMikaeldelCorro
 
MCM FUNCTIONS BLACKBOARD COMPATIBILITY
MCM FUNCTIONS BLACKBOARD COMPATIBILITYMCM FUNCTIONS BLACKBOARD COMPATIBILITY
MCM FUNCTIONS BLACKBOARD COMPATIBILITYJosefMikaeldelCorro1
 
computer notes - Data Structures - 8
computer notes - Data Structures - 8computer notes - Data Structures - 8
computer notes - Data Structures - 8ecomputernotes
 
multiple linear regression
multiple linear regressionmultiple linear regression
multiple linear regressionAkhilesh Joshi
 
Functional Programming in Swift
Functional Programming in SwiftFunctional Programming in Swift
Functional Programming in SwiftSaugat Gautam
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rathSANTOSH RATH
 
Project of data structure
Project of data structureProject of data structure
Project of data structureUmme habiba
 

What's hot (20)

Formal methods Project Report for the support of slides uploaded
Formal methods Project Report for the support of slides uploaded Formal methods Project Report for the support of slides uploaded
Formal methods Project Report for the support of slides uploaded
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
The Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterateThe Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterate
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
Chapter iii(advance function)
Chapter iii(advance function)Chapter iii(advance function)
Chapter iii(advance function)
 
The Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterateThe Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterate
 
Functions & Procedures [7]
Functions & Procedures [7]Functions & Procedures [7]
Functions & Procedures [7]
 
Concept of c
Concept of cConcept of c
Concept of c
 
Part II: 2-Dimensional Array file name: lab1part2.cpp (10 points) Write a C++...
Part II: 2-Dimensional Array file name: lab1part2.cpp (10 points) Write a C++...Part II: 2-Dimensional Array file name: lab1part2.cpp (10 points) Write a C++...
Part II: 2-Dimensional Array file name: lab1part2.cpp (10 points) Write a C++...
 
BB - Functions (Operations and Piecewise)
BB  - Functions (Operations and Piecewise)BB  - Functions (Operations and Piecewise)
BB - Functions (Operations and Piecewise)
 
MCM FUNCTIONS BLACKBOARD COMPATIBILITY
MCM FUNCTIONS BLACKBOARD COMPATIBILITYMCM FUNCTIONS BLACKBOARD COMPATIBILITY
MCM FUNCTIONS BLACKBOARD COMPATIBILITY
 
computer notes - Data Structures - 8
computer notes - Data Structures - 8computer notes - Data Structures - 8
computer notes - Data Structures - 8
 
multiple linear regression
multiple linear regressionmultiple linear regression
multiple linear regression
 
Team 6
Team 6Team 6
Team 6
 
Queue
QueueQueue
Queue
 
Functional Programming in Swift
Functional Programming in SwiftFunctional Programming in Swift
Functional Programming in Swift
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
 
Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions
 
knn classification
knn classificationknn classification
knn classification
 

Similar to Java -lec-5

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.pdfoptokunal1
 
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
 
Computer java programs
Computer java programsComputer java programs
Computer java programsADITYA BHARTI
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptxKimVeeL
 
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfThrowing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfaquazac
 
Core java pract_sem iii
Core java pract_sem iiiCore java pract_sem iii
Core java pract_sem iiiNiraj Bharambe
 
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
 
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdfSumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdfankkitextailes
 
CountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdfCountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdfpremsrivastva8
 
Prompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfPrompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfFootageetoffe16
 
9)Answerimport java.util.; import java.lang.; import java.pdf
9)Answerimport java.util.; import java.lang.; import java.pdf9)Answerimport java.util.; import java.lang.; import java.pdf
9)Answerimport java.util.; import java.lang.; import java.pdfanandf0099
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptxKimVeeL
 

Similar to Java -lec-5 (19)

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 programs
Java programsJava programs
Java programs
 
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
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
 
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdfThrowing.javaimport java.util.InputMismatchException; import jav.pdf
Throwing.javaimport java.util.InputMismatchException; import jav.pdf
 
Core java pract_sem iii
Core java pract_sem iiiCore java pract_sem iii
Core java pract_sem iii
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
Oot practical
Oot practicalOot practical
Oot practical
 
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
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
 
Computer programming 2 chapter 1-lesson 2
Computer programming 2  chapter 1-lesson 2Computer programming 2  chapter 1-lesson 2
Computer programming 2 chapter 1-lesson 2
 
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdfSumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
SumNumbers.java import java.util.Scanner;public class SumNumbe.pdf
 
CountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdfCountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdf
 
Prompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfPrompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdf
 
9)Answerimport java.util.; import java.lang.; import java.pdf
9)Answerimport java.util.; import java.lang.; import java.pdf9)Answerimport java.util.; import java.lang.; import java.pdf
9)Answerimport java.util.; import java.lang.; import java.pdf
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Java -lec-5

  • 1. JAVA "WRITE ONCE, RUN ANYWHERE” Lec--5 By: Zubair Khalid
  • 2. Java £ Java Math Class £ Java Random Number Class
  • 3. Java math class contains the following useful methods Java Math Class £ Power £ Absolute £ Ceil £ Floor £ Maximum £ Minimum £ Square root
  • 4. Power This method is used for calculating power of a number Math.pow (a, b); Number Desired power of that number
  • 5. Power (Example) Import java.Util.Scanner; Class c1{ Public static void main(string[] args) { system.Out.Println("please enter A number"); Scanner input=new scanner(system.In); Int number,power; Number=input.Nextint(); System.Out.Println("please enter power"); Power=input.Nextint(); System.Out.Println("power of "+number+" is "+math.Pow(number, power)); } }
  • 6. Absolute £ it shows the absolute value of a number. £ If we enter -ve or +ve value it will show us absolute value. Math.abs (a); Number
  • 7. Absolute (Example) Import java.Util.*; Class c2{ Public static void main(string[] args) { int number; Scanner scan=new scanner(system.In); System.Out.Println("please enter A number:"); Number=scan.Nextint(); System.Out.Println(math.Abs(number)); } }
  • 8. Ceil It rounds up the number like if we enter (7.1-7.9) the output always will be 8.0. Math.ceil (a); Number
  • 9. Ceil (Example) Import java.Util.Scanner; Class c3{ Public static void main(string[] args) { double number; Scanner scan=new scanner(system.In); System.Out.Println("please enter A number:"); Number=scan.Nextdouble(); System.Out.Println(math.Ceil(number)); Scan.Close(); } }
  • 10. Floor it rounds down the number like if we enter (7.1-7.9) the output always will be 7.0. Math.floor (a); Number
  • 11. Floor (Example) import java.util.Scanner; class c4{ public static void main(String[] args) { double number; Scanner scan=new Scanner(System.in); System.out.println("Please Enter A Number:"); number=scan.nextDouble(); System.out.println(Math.floor(number)); scan.close(); } }
  • 12. Maximum it takes two numbers and output the variable which is maximum. Math.max (a, b); Number
  • 13. Maximum (Example) import java.util.Scanner; class c5{ public static void main(String[] args) { double number; Scanner scan=new Scanner(System.in); System.out.println("Please Enter A Number:"); number=scan.nextDouble(); System.out.println(Math.max(1.2,5.2)); scan.close(); } }
  • 14. Minimum it takes two numbers and output the variable which is minimum. Math.min (a, b); Number
  • 15. Minimum (Example) import java.util.Scanner; class c6{ public static void main(String[] args) { double number; Scanner scan=new Scanner(System.in); System.out.println("Please Enter A Number:"); number=scan.nextDouble(); System.out.println(Math.min(1.2,5.2)); scan.close(); } }
  • 16. Square root it takes a number as input and output the square root of that number. Math.sqrt (a); Number
  • 17. Square root (Example) import java.util.Scanner; class c7{ public static void main(String[] args) { double number; Scanner scan=new Scanner(System.in); System.out.println("Please Enter A Number:"); number=scan.nextDouble(); System.out.println(Math.sqrt(number)); scan.close(); } }
  • 18. import java.util.Random; class c8{ public static void main(String[] args) { Random dice=new Random(); int number; for(int counter=1;counter<=10;counter++) { number=dice.nextInt(6); System.out.println(number+""); } } } Java Random Number Class Example: