SlideShare a Scribd company logo
1 of 4
Download to read offline
Learning the java language
Workshop 1:
 How to use primitive Java types, operators on those types, and expressions formed with
those types
 How to use loop and other flow control structures
 How to use array
Q1. Write a program that performs the following tasks:
1. Input 4 real numbers a, b, c and x.
2. Calculate S1 = ax2
+ bx + c.
3. Calculate S2 = acb 42
 if b - 4ac > 0, otherwise S2 = 0
4. Re-input a, b and c. Check whether a, b and c are sides of a triangle or not.
5. If a, b, c are sides of a triangle, then calculate its perimeter and area, otherwise display on
the screen a message "a, b, c are not side of a triangle". The area is calculated by the
Heron formula below:
S1 = ))()(( cpbpapp  , where
2
)( cba
p


Q2. Write a program that performs the following tasks:
1. Input an integer number n, where n > 5 (If n≤ 5 then
prompt a user to re-enter). Then calculate
2. S1 = 1 + 2 + 3 + ... + n.
3. S2 = n!
4. S3 =1+
2
1
+
3
1
+...+
n
1
.
5. Re-input n. Check whether n is a prime number or not.
Q3. Write a program to accept 2 integer numbers m and n, then:
1. Display all prime common dividers of them.
2. Find the greatest common divider (GCD) of them.
3. Find the least common multiple (LCM) of them.
Q4. Write a program that performs the following tasks:
1. Input an integer number n (check input validation), then
2. Display n in binary number format.
3. Re-input n (not check input validation). Calculate sum of all digits of n.
4. Find the number m, which is the reverse of n.
Q5. Write a program to accept 3 real numbers a, b and c, then
Solve the quadratic equation ax2
+ bx + c = 0.
Q6. Write a program to accept 2 integer numbers m and n, where m < n then
Display all palindrom numbers in the interval [m.n]. (A palindromic number or numeral
palindrome is a number that remains the same when its digits are reversed, e.g. 16461)
Q7. Write a program that performs the following tasks:
1. Write function with prototype
double myExp(double x, int n);
which calculate ex
approximately by the formula:
ex
~ S = 1+
!1
x
+
!2
2
x
+ ... +
!n
xn
2. Write function with prototype
double myExp(double x, double epsi);
which calculate and return ex
approximately by the formula:
ex
~ S = 1+
!1
x
+
!2
2
x
+ ... +
!n
xn
here n is the first integer for which |
!n
xn
|  epsi is satisfied.
3 . Write function with prototype:
double myPi(double epsi);
which calculates and return the value PI approximately by the formula:
 ~ S = 4* (1-
3
1
+
5
1
-
7
1
+...+(-1)n
12
1
n
)
here n is the first integer for which |
12
1
n
|  epsi is satisfied.
4. Write function with prototype:
double mySin(double x, double epsi);
which calculates and return the value sin(x) approximately by the formula:
sin(x) =
!1
x
-
!3
3
x
+
!5
5
x
-... +(-1)n
)!12(
)12(


n
x n
here n is the first integer for which |
12
1
n
|  epsi is satisfied.
5. Write function with prototype:
double myCos(double x, double epsi);
which calculates and return the value cos(x) approximately by the formula:
cos(x) = 1 -
!2
2
x
+
!4
4
x
-... +(-1)n
)!2(
2
n
x n
here n is the first integer for which |
)!2(
2
n
x n
|  epsi is satisfied.
6. Write a Java program that performs the following operations on an array of integers in the
main function:
- Input data (number of elements, the elements of the arrays)
- Display all elements
- Sort all numbers in ascending order
- Find the maximum value
Q8. Write a menu driven program with the options below:
Choose one of the following option:
1. Input 2 polynomials Pn
(x) and Qm
(x)
2. Calculate Pn
(x0) và Qm
(x0)
3. The derivatives of polynomials
4. Calculate Pn
(x) + Qm
(x)
5. Calculate Pn
(x) - Qm
(x)
6. Calculate Pn
(x) x Qm
(x)
7. Calculate Pn
(x) / Qm
(x)
Q9. Financial Calculator
Design and code a program that performs two financial calculations: future value and present
value. Your program prompts for and accepts a principal amount, an interest rate per year, and
the number of years. If the number of periods is zero then the calculated amount is a present
value (principal).
Suppose Pn is an amount after n years, thus we have
Pn = Pn-1 + rate*Pn-1 = (1 + rate)*Pn-1
It easy to show that
Pn = (1 + rate)n
P0
where P0 is a principal.
Design your program according to structured design principles and include a function that can be
used in both calculations as well as in other applications.
Preface your function header with a comprehensive description of the function purpose, the
function parameters and the function return value.
The output from your program should look something like:
Q10. Write a menu driven program with the options below:
Choose one of the following option:
1. Input a string
2. Split a string into words
3. Remove redundant soaces
4. Check valid name
5. Exit
Your selection (0->5):
Q11. The correct sentence: Capitalize the First Word in a Sentence, one space between words,
a space following commas and periods.

More Related Content

What's hot

Number system.pdf
Number system.pdfNumber system.pdf
Number system.pdfDeepuGuna
 
Sorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - NotesSorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - NotesOmprakash Chauhan
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - NotesOmprakash Chauhan
 
A1 11 functions
A1 11 functionsA1 11 functions
A1 11 functionsvhiggins1
 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - NotesOmprakash Chauhan
 
Calculus- Basics
Calculus- BasicsCalculus- Basics
Calculus- BasicsRabin BK
 
What is Function?
What is Function?What is Function?
What is Function?ahmad240
 
Derivative3
Derivative3Derivative3
Derivative3vpaci
 
Java Tutorial: Part 4 - Data and Calculations
Java Tutorial: Part 4 - Data and CalculationsJava Tutorial: Part 4 - Data and Calculations
Java Tutorial: Part 4 - Data and CalculationsSvetlin Nakov
 
Writea program that defines a template function named add(). Thisfunction tak...
Writea program that defines a template function named add(). Thisfunction tak...Writea program that defines a template function named add(). Thisfunction tak...
Writea program that defines a template function named add(). Thisfunction tak...licservernoida
 
November 2, 2015
November 2, 2015November 2, 2015
November 2, 2015khyps13
 
Number System in CoMpUtEr
Number System in CoMpUtErNumber System in CoMpUtEr
Number System in CoMpUtErvishal bansal
 
Number system with conversions www.eakanchha.com
Number system with conversions www.eakanchha.comNumber system with conversions www.eakanchha.com
Number system with conversions www.eakanchha.comAkanchha Agrawal
 

What's hot (20)

Number system.pdf
Number system.pdfNumber system.pdf
Number system.pdf
 
Loop Statements [5] M
Loop Statements [5] MLoop Statements [5] M
Loop Statements [5] M
 
Sorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - NotesSorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - Notes
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
A1 11 functions
A1 11 functionsA1 11 functions
A1 11 functions
 
Booth Multiplier
Booth MultiplierBooth Multiplier
Booth Multiplier
 
Number System
Number SystemNumber System
Number System
 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - Notes
 
Calculus- Basics
Calculus- BasicsCalculus- Basics
Calculus- Basics
 
What is Function?
What is Function?What is Function?
What is Function?
 
Derivative3
Derivative3Derivative3
Derivative3
 
Java Tutorial: Part 4 - Data and Calculations
Java Tutorial: Part 4 - Data and CalculationsJava Tutorial: Part 4 - Data and Calculations
Java Tutorial: Part 4 - Data and Calculations
 
C programming slide c05
C programming slide c05C programming slide c05
C programming slide c05
 
number system
number systemnumber system
number system
 
Writea program that defines a template function named add(). Thisfunction tak...
Writea program that defines a template function named add(). Thisfunction tak...Writea program that defines a template function named add(). Thisfunction tak...
Writea program that defines a template function named add(). Thisfunction tak...
 
November 2, 2015
November 2, 2015November 2, 2015
November 2, 2015
 
Number System and Boolean Algebra
Number System and Boolean AlgebraNumber System and Boolean Algebra
Number System and Boolean Algebra
 
Number System in CoMpUtEr
Number System in CoMpUtErNumber System in CoMpUtEr
Number System in CoMpUtEr
 
Dynamic allocation
Dynamic allocationDynamic allocation
Dynamic allocation
 
Number system with conversions www.eakanchha.com
Number system with conversions www.eakanchha.comNumber system with conversions www.eakanchha.com
Number system with conversions www.eakanchha.com
 

Similar to Exercise1 java

M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docxM166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docxinfantsuk
 
A New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmA New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmJim Jimenez
 
Functions Practice Sheet.docx
Functions Practice Sheet.docxFunctions Practice Sheet.docx
Functions Practice Sheet.docxSwatiMishra364461
 
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfCD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfRajJain516913
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments rajni kaushal
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualAnkit Kumar
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning materialArthyR3
 
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18HIMANSHU .
 
Solution of matlab chapter 4
Solution of matlab chapter 4Solution of matlab chapter 4
Solution of matlab chapter 4AhsanIrshad8
 
Class 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibClass 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibMarc Gouw
 

Similar to Exercise1 java (20)

M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docxM166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
M166Calculus” ProjectDue Wednesday, December 9, 2015PROJ.docx
 
A01
A01A01
A01
 
Lecture 7.pptx
Lecture 7.pptxLecture 7.pptx
Lecture 7.pptx
 
Programming qns
Programming qnsProgramming qns
Programming qns
 
Cse cpl manual-2016
Cse cpl manual-2016Cse cpl manual-2016
Cse cpl manual-2016
 
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORYGE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
 
A New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmA New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring Algorithm
 
Functions Practice Sheet.docx
Functions Practice Sheet.docxFunctions Practice Sheet.docx
Functions Practice Sheet.docx
 
A02
A02A02
A02
 
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfCD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning material
 
Programming Fundamental handouts
Programming Fundamental handoutsProgramming Fundamental handouts
Programming Fundamental handouts
 
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
COMPUTER SCIENCE INVESTIGATORY PROJECT 2017-18
 
C important questions
C important questionsC important questions
C important questions
 
Solution of matlab chapter 4
Solution of matlab chapter 4Solution of matlab chapter 4
Solution of matlab chapter 4
 
Loops in Python
Loops in PythonLoops in Python
Loops in Python
 
Class 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibClass 8b: Numpy & Matplotlib
Class 8b: Numpy & Matplotlib
 
C code examples
C code examplesC code examples
C code examples
 

More from NguynMinh294

Slide An toàn mạng nâng cao PTIT
Slide An toàn mạng nâng cao PTITSlide An toàn mạng nâng cao PTIT
Slide An toàn mạng nâng cao PTITNguynMinh294
 
Phân tích thiết kế hệ thống thông tin PTIT
Phân tích thiết kế hệ thống thông tin PTIT Phân tích thiết kế hệ thống thông tin PTIT
Phân tích thiết kế hệ thống thông tin PTIT NguynMinh294
 
Bài giảng mật mã học cơ sở PTIT
Bài giảng mật mã học cơ sở PTITBài giảng mật mã học cơ sở PTIT
Bài giảng mật mã học cơ sở PTITNguynMinh294
 
Bài giảng an toàn ứng dụng web và csdl PTIT
Bài giảng an toàn ứng dụng web và csdl PTITBài giảng an toàn ứng dụng web và csdl PTIT
Bài giảng an toàn ứng dụng web và csdl PTITNguynMinh294
 
Bài giảng an toàn ứng dụng web và csdl PTIT
Bài giảng an toàn ứng dụng web và csdl PTITBài giảng an toàn ứng dụng web và csdl PTIT
Bài giảng an toàn ứng dụng web và csdl PTITNguynMinh294
 
Bài giảng kiểm thử xâm nhập PTIT
Bài giảng kiểm thử xâm nhập PTITBài giảng kiểm thử xâm nhập PTIT
Bài giảng kiểm thử xâm nhập PTITNguynMinh294
 
Bài giảng ký thuật theo dõi giám sát mạng PTIT
Bài giảng ký thuật theo dõi giám sát mạng PTITBài giảng ký thuật theo dõi giám sát mạng PTIT
Bài giảng ký thuật theo dõi giám sát mạng PTITNguynMinh294
 
Giáo trình mạng máy tính PTIT
Giáo trình mạng máy tính PTITGiáo trình mạng máy tính PTIT
Giáo trình mạng máy tính PTITNguynMinh294
 
Ktvxl chuong 5 - cac phuong phap vao ra du lieu
Ktvxl chuong 5 - cac phuong phap vao ra du lieuKtvxl chuong 5 - cac phuong phap vao ra du lieu
Ktvxl chuong 5 - cac phuong phap vao ra du lieuNguynMinh294
 
Ktvxl chuong 4 - phoi ghep
Ktvxl chuong 4 - phoi ghepKtvxl chuong 4 - phoi ghep
Ktvxl chuong 4 - phoi ghepNguynMinh294
 
Ktvxl chuong 3 - hop ngu 8088
Ktvxl chuong 3 - hop ngu 8088Ktvxl chuong 3 - hop ngu 8088
Ktvxl chuong 3 - hop ngu 8088NguynMinh294
 
Ktvxl chuong 2 - 8086-8088
Ktvxl chuong 2 - 8086-8088Ktvxl chuong 2 - 8086-8088
Ktvxl chuong 2 - 8086-8088NguynMinh294
 
Ktvxl chuong 1 - tong quan
Ktvxl chuong 1 - tong quanKtvxl chuong 1 - tong quan
Ktvxl chuong 1 - tong quanNguynMinh294
 
bài giảng ký thuật vi xử lý PTIT
bài giảng ký thuật vi xử lý PTITbài giảng ký thuật vi xử lý PTIT
bài giảng ký thuật vi xử lý PTITNguynMinh294
 
đề thi java ptit
đề thi java ptitđề thi java ptit
đề thi java ptitNguynMinh294
 
Java exercises part 2
Java exercises part 2Java exercises part 2
Java exercises part 2NguynMinh294
 
Java exercises part 1
Java exercises part 1Java exercises part 1
Java exercises part 1NguynMinh294
 
Giáo trình hệ điều hành PTIT
Giáo trình hệ điều hành PTITGiáo trình hệ điều hành PTIT
Giáo trình hệ điều hành PTITNguynMinh294
 

More from NguynMinh294 (20)

Slide An toàn mạng nâng cao PTIT
Slide An toàn mạng nâng cao PTITSlide An toàn mạng nâng cao PTIT
Slide An toàn mạng nâng cao PTIT
 
Phân tích thiết kế hệ thống thông tin PTIT
Phân tích thiết kế hệ thống thông tin PTIT Phân tích thiết kế hệ thống thông tin PTIT
Phân tích thiết kế hệ thống thông tin PTIT
 
Bài giảng mật mã học cơ sở PTIT
Bài giảng mật mã học cơ sở PTITBài giảng mật mã học cơ sở PTIT
Bài giảng mật mã học cơ sở PTIT
 
Bài giảng an toàn ứng dụng web và csdl PTIT
Bài giảng an toàn ứng dụng web và csdl PTITBài giảng an toàn ứng dụng web và csdl PTIT
Bài giảng an toàn ứng dụng web và csdl PTIT
 
Bài giảng an toàn ứng dụng web và csdl PTIT
Bài giảng an toàn ứng dụng web và csdl PTITBài giảng an toàn ứng dụng web và csdl PTIT
Bài giảng an toàn ứng dụng web và csdl PTIT
 
Bài giảng kiểm thử xâm nhập PTIT
Bài giảng kiểm thử xâm nhập PTITBài giảng kiểm thử xâm nhập PTIT
Bài giảng kiểm thử xâm nhập PTIT
 
Bài giảng ký thuật theo dõi giám sát mạng PTIT
Bài giảng ký thuật theo dõi giám sát mạng PTITBài giảng ký thuật theo dõi giám sát mạng PTIT
Bài giảng ký thuật theo dõi giám sát mạng PTIT
 
Giáo trình mạng máy tính PTIT
Giáo trình mạng máy tính PTITGiáo trình mạng máy tính PTIT
Giáo trình mạng máy tính PTIT
 
Ktvxl chuong 5 - cac phuong phap vao ra du lieu
Ktvxl chuong 5 - cac phuong phap vao ra du lieuKtvxl chuong 5 - cac phuong phap vao ra du lieu
Ktvxl chuong 5 - cac phuong phap vao ra du lieu
 
Ktvxl chuong 4 - phoi ghep
Ktvxl chuong 4 - phoi ghepKtvxl chuong 4 - phoi ghep
Ktvxl chuong 4 - phoi ghep
 
Ktvxl chuong 3 - hop ngu 8088
Ktvxl chuong 3 - hop ngu 8088Ktvxl chuong 3 - hop ngu 8088
Ktvxl chuong 3 - hop ngu 8088
 
Ktvxl chuong 2 - 8086-8088
Ktvxl chuong 2 - 8086-8088Ktvxl chuong 2 - 8086-8088
Ktvxl chuong 2 - 8086-8088
 
Ktvxl chuong 1 - tong quan
Ktvxl chuong 1 - tong quanKtvxl chuong 1 - tong quan
Ktvxl chuong 1 - tong quan
 
bài giảng ký thuật vi xử lý PTIT
bài giảng ký thuật vi xử lý PTITbài giảng ký thuật vi xử lý PTIT
bài giảng ký thuật vi xử lý PTIT
 
đề thi java ptit
đề thi java ptitđề thi java ptit
đề thi java ptit
 
Java exercises part 2
Java exercises part 2Java exercises part 2
Java exercises part 2
 
Java exercises part 1
Java exercises part 1Java exercises part 1
Java exercises part 1
 
Bai tap3 java
Bai tap3 javaBai tap3 java
Bai tap3 java
 
Bai tap2 java
Bai tap2 javaBai tap2 java
Bai tap2 java
 
Giáo trình hệ điều hành PTIT
Giáo trình hệ điều hành PTITGiáo trình hệ điều hành PTIT
Giáo trình hệ điều hành PTIT
 

Recently uploaded

भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
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
 
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
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
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
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
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
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.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
 
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
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.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
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

Exercise1 java

  • 1. Learning the java language Workshop 1:  How to use primitive Java types, operators on those types, and expressions formed with those types  How to use loop and other flow control structures  How to use array Q1. Write a program that performs the following tasks: 1. Input 4 real numbers a, b, c and x. 2. Calculate S1 = ax2 + bx + c. 3. Calculate S2 = acb 42  if b - 4ac > 0, otherwise S2 = 0 4. Re-input a, b and c. Check whether a, b and c are sides of a triangle or not. 5. If a, b, c are sides of a triangle, then calculate its perimeter and area, otherwise display on the screen a message "a, b, c are not side of a triangle". The area is calculated by the Heron formula below: S1 = ))()(( cpbpapp  , where 2 )( cba p   Q2. Write a program that performs the following tasks: 1. Input an integer number n, where n > 5 (If n≤ 5 then prompt a user to re-enter). Then calculate 2. S1 = 1 + 2 + 3 + ... + n. 3. S2 = n! 4. S3 =1+ 2 1 + 3 1 +...+ n 1 . 5. Re-input n. Check whether n is a prime number or not. Q3. Write a program to accept 2 integer numbers m and n, then: 1. Display all prime common dividers of them. 2. Find the greatest common divider (GCD) of them. 3. Find the least common multiple (LCM) of them. Q4. Write a program that performs the following tasks: 1. Input an integer number n (check input validation), then 2. Display n in binary number format. 3. Re-input n (not check input validation). Calculate sum of all digits of n. 4. Find the number m, which is the reverse of n. Q5. Write a program to accept 3 real numbers a, b and c, then Solve the quadratic equation ax2 + bx + c = 0. Q6. Write a program to accept 2 integer numbers m and n, where m < n then Display all palindrom numbers in the interval [m.n]. (A palindromic number or numeral palindrome is a number that remains the same when its digits are reversed, e.g. 16461)
  • 2. Q7. Write a program that performs the following tasks: 1. Write function with prototype double myExp(double x, int n); which calculate ex approximately by the formula: ex ~ S = 1+ !1 x + !2 2 x + ... + !n xn 2. Write function with prototype double myExp(double x, double epsi); which calculate and return ex approximately by the formula: ex ~ S = 1+ !1 x + !2 2 x + ... + !n xn here n is the first integer for which | !n xn |  epsi is satisfied. 3 . Write function with prototype: double myPi(double epsi); which calculates and return the value PI approximately by the formula:  ~ S = 4* (1- 3 1 + 5 1 - 7 1 +...+(-1)n 12 1 n ) here n is the first integer for which | 12 1 n |  epsi is satisfied. 4. Write function with prototype: double mySin(double x, double epsi); which calculates and return the value sin(x) approximately by the formula: sin(x) = !1 x - !3 3 x + !5 5 x -... +(-1)n )!12( )12(   n x n here n is the first integer for which | 12 1 n |  epsi is satisfied. 5. Write function with prototype: double myCos(double x, double epsi); which calculates and return the value cos(x) approximately by the formula: cos(x) = 1 - !2 2 x + !4 4 x -... +(-1)n )!2( 2 n x n here n is the first integer for which | )!2( 2 n x n |  epsi is satisfied. 6. Write a Java program that performs the following operations on an array of integers in the main function: - Input data (number of elements, the elements of the arrays)
  • 3. - Display all elements - Sort all numbers in ascending order - Find the maximum value Q8. Write a menu driven program with the options below: Choose one of the following option: 1. Input 2 polynomials Pn (x) and Qm (x) 2. Calculate Pn (x0) và Qm (x0) 3. The derivatives of polynomials 4. Calculate Pn (x) + Qm (x) 5. Calculate Pn (x) - Qm (x) 6. Calculate Pn (x) x Qm (x) 7. Calculate Pn (x) / Qm (x) Q9. Financial Calculator Design and code a program that performs two financial calculations: future value and present value. Your program prompts for and accepts a principal amount, an interest rate per year, and the number of years. If the number of periods is zero then the calculated amount is a present value (principal). Suppose Pn is an amount after n years, thus we have Pn = Pn-1 + rate*Pn-1 = (1 + rate)*Pn-1 It easy to show that Pn = (1 + rate)n P0 where P0 is a principal. Design your program according to structured design principles and include a function that can be used in both calculations as well as in other applications. Preface your function header with a comprehensive description of the function purpose, the function parameters and the function return value. The output from your program should look something like:
  • 4. Q10. Write a menu driven program with the options below: Choose one of the following option: 1. Input a string 2. Split a string into words 3. Remove redundant soaces 4. Check valid name 5. Exit Your selection (0->5): Q11. The correct sentence: Capitalize the First Word in a Sentence, one space between words, a space following commas and periods.