SlideShare a Scribd company logo
1 of 67
Structure programmingStructure programming
Java Programming – PracticeJava Programming – Practice
part -1part -1
Faculty of Physical and Basic Education
Computer Science
By: Msc. Karwan M. Kareem
www.karwanit.com
karwan@karwanit.com
2016 - 2017
1
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Installing JDKInstalling JDK
1- go to JDK folder
2- Right click on JDK icon and click
open
2
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
3- Waiting for configuring the
installer ..
3
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
4- click on next button..
4
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
5- choose the installation folder..
6 – click on next button …
5
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
7 – click on Install button …
6
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
8 – Waiting for installing all JDK
files…
7
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
8 – Installation completed
successfully and click on
finish button to finish the
JDK…
8
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
1- Click on the Eclipse – Shortcut
or Eclipse -Icon
2- Choose a workspace folder to
use for this session
3- Click ok
Starting to write first Java program ....
9
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
4- go to file list  new Java project
5- write your project name
10
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
6- click next button
7- click finish
11
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
8- go to the project  right click new  class
9- write name for your class
10- choose the modifier “public”
12
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
11- choose the method
12- click finish
13
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
13- write your Java Program
14- click on run and get
the result
14
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
1- Input: Define all variables
1- process
1- Output: print results
Example: Write a Java program to calculate two numbersExample: Write a Java program to calculate two numbers
15
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Example: Write a Java program to compute the area of the circle
1- allocate memory for radius
2- allocate memory for area
3- compute
area and
assign it to
variable area
4- print a
message to the
console
16
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Write a Java program to compute the area
of the circle ( use JOptionPane)
Example: Write a Java program to print out full name, with use theExample: Write a Java program to print out full name, with use the
scanner classscanner class to handle input from a user.to handle input from a user.
import java.util.Scanner;import java.util.Scanner;
public class FullName {public class FullName {
public static void main(String[] args) {public static void main(String[] args) {
// TODO Auto-generated method stub// TODO Auto-generated method stub
Scanner In = new Scanner (System.Scanner In = new Scanner (System.in);in);
System.System.out.println("enter first name:");out.println("enter first name:");
String first_name = In.next();String first_name = In.next();
System.System.out.println("enter last name");out.println("enter last name");
String last_name=In.next();String last_name=In.next();
System.System.out.println("Your full name is: " + first_name +" "+ last_name);out.println("Your full name is: " + first_name +" "+ last_name);
} }} }
Create new Scanner Object
Read first input
Read second input
18
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Example: Write a Java program to print out your profile,Example: Write a Java program to print out your profile,
with use thewith use the scanner classscanner class to handle input from a userto handle input from a user
import java.util.Scanner;
public class FullName {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner In = new Scanner (System.in);
System.out.println("enter first name:");
String first_name = In.next();
System.out.println("enter last name ");
String last_name=In.next();
System.out.println("enter your age ");
int age=In.nextInt();
System.out.println("enter your adress ");
String address=In.next();
System.out.println("enter your gender ");
String gender=In.next();
System.out.println("Your full name is: " + first_name + " " + last_name);
System.out.println("Your age is: " + age);
System.out.println("Your address: " + address);
System.out.println("Your gender is: " + gender); } }
Create new Scanner Object
Read data from consol
Print all variables
19
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Example: Write a program that obtains Current Date &
Time
This is very easy to get current date and time in Java. You
can use a simple Date object with toString() method to
print current date and time as follows:
import java.util.Date;
public class DateDemo {
public static void main(String args[]) {
// Instantiate a Date object
Date date = new Date();
// display time and date using toString()
System.out.println(date.toString());
}
}
Create new Date Object
Using toString to print current date
and time
20
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
)
94
(9
))(5(10
5
43
y
x
xx
cbayx +
++
++−
−
+
Example: Write a JAVA program to find out the output of theExample: Write a JAVA program to find out the output of the
following rulesfollowing rules
import java.util.Scanner;
public class arth {
public static void main(String[] args) {
Scanner In = new Scanner (System.in);
System.out.println("enter number a ");
int a=In.nextInt();
System.out.println("enter number b ");
int b=In.nextInt();
System.out.println("enter number c ");
int c=In.nextInt();
System.out.println("enter number x ");
int x=In.nextInt();
System.out.println("enter number y ");
int y=In.nextInt();
double outPut = (3 + 4 * x) / 5 - (10 * (y-5)*(a+b+c))/x +9*(4/x+(9+x/y));
System.out.println("the result is :" + outPut); } }
Create new Scanner Object
Read data from consol
21
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 1: Write a Java program to compute the area of the
Trapezium, with use the scanner class to handle input from a
user, and JOptionPane to print the result.
22
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 2:AQuestion 2:A: Write a Java program to compute the area of the: Write a Java program to compute the area of the
SectorSector,, with use thewith use the scanner classscanner class to handle input from a user,to handle input from a user,
andand JOptionPaneJOptionPane to print the result.to print the result.
23
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 2:BQuestion 2:B: Write a Java program to compute the area of the: Write a Java program to compute the area of the
top part of the circle,top part of the circle, with use thewith use the JOptionPaneJOptionPane to handle inputto handle input
from a user, andfrom a user, and consoleconsole to print the result.to print the result.
24
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
1
2
3
4
5
6
25
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 3Question 3: Write a Java program to compute the area of the: Write a Java program to compute the area of the
EllipseEllipse,, with use thewith use the scanner classscanner class to handle input from a user,to handle input from a user,
andand JOptionPaneJOptionPane to print the result.to print the result.
26
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 4:A:Question 4:A: Write a JAVA program to find the real valueWrite a JAVA program to find the real value
output of the following rules.output of the following rules.
- UseUse Scanner classScanner class to handle input from a user.to handle input from a user.
- UseUse JOptionPaneJOptionPane to print the result.to print the result.
)
4
(9
))(5(10
5
4
h
L
LL
cbahL
y ++
++−
−=
m
h
k
dk
hk
b +++
−
−=
4)5(11
5
15
27
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
28
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 4:B:Question 4:B: Write a JAVA program to find the “real value” output of theWrite a JAVA program to find the “real value” output of the
following rules.following rules. - UseUse Scanner classScanner class to handle input from a user.to handle input from a user.
- UseUse JOptionPaneJOptionPane to print the result.to print the result.
10
10
23
−++=
h
x
L
xx
y
Question 5:Question 5: Write a Java program to print out your profile,Write a Java program to print out your profile,
with use thewith use the scanner classscanner class to handle input from a userto handle input from a user
outputoutput
Name: Karwan M. KareemName: Karwan M. Kareem
Gender: MaleGender: Male
Age: 30Age: 30
Email address: mailExample@yahoo.comEmail address: mailExample@yahoo.com
Address: SulAddress: Sul
Note: any thingNote: any thing
29
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 6: Write a java program to find theQuestion 6: Write a java program to find the SumSum andand
AverageAverage of five lessons, and print them out with yourof five lessons, and print them out with your
name. is he/ she good or bad student (Use JOptionPane forname. is he/ she good or bad student (Use JOptionPane for
Input)Input)
OUTPUT :OUTPUT :
Your name : Karwan M. KareemYour name : Karwan M. Kareem
Lessons1=55Lessons1=55
Lessons2=55Lessons2=55
Lessons3=55Lessons3=55
Lessons4=55Lessons4=55
Lessons5=55Lessons5=55
The sum = 275The sum = 275
The average = 55The average = 55
He is goodHe is good
30
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
31
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 7: Write a Java program to compare three numbersQuestion 7: Write a Java program to compare three numbers
and find largest out of three (Use JOptionPane or Scanner).and find largest out of three (Use JOptionPane or Scanner).
X greater then y and x greater then zX greater then y and x greater then z  "First number is largest""First number is largest"
Y greater then x and y greater then zY greater then x and y greater then z  "Second number is largest""Second number is largest"
zz greater thengreater then xx andand zz greater thengreater then yy  "Third number is largest""Third number is largest"
ElseElse  "Entered numbers are equals...""Entered numbers are equals..."
32
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
33
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 8: write the program in Java aboutQuestion 8: write the program in Java about if elseif else the programthe program
should ask the user to enter the total marks out of 100, and thenshould ask the user to enter the total marks out of 100, and then
display the letter grade on the screen (Use Scanner class)display the letter grade on the screen (Use Scanner class)
* Grade Rules:* Grade Rules:
0-490-49  D gradD grad
50-5550-55  C gradC grad
56-6056-60  C+ gradC+ grad
61-7061-70  B gradB grad
71-7571-75  B+ gradB+ grad
76-8576-85  A gradA grad
86-10086-100  A+ gradA+ grad
Else “you have error …”Else “you have error …”
34
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
35
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
36
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 9: Write a java program to implement a Vote System,
with use JOptionPane for input and console for outpt
Name : karwan kareem
address: Sul / Hilan City
gender: Male
age: 30
Age > 0 and age <18
print  “cannot vote”
age > 18 and age < 100
print  “can vote “
else
print “you have error ”
37
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
38
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 10: Write a java program about “Good student “
(use JOptionPane)
If gender is male and grade is 70 and above: display “Good boy"
If gender is female and grade is 70 above: display “Good girl"
but if grade is below 70 regardless of gender: display “Bad child"
39
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 11: write a java program to create “size-system”
(Use JOptionPane).
If size equal to 1  X-small
If size equal to 2  small
If size equal to 3  Medium
If size equal to 4  large
If size equal to 5  X-large
41
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
42
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 12: write the output of the following Java codes.
43
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 13: write the output of the following Java codes.
44
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 13:B: write the output of the following Java codes.
45
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 14: write a java program to print out ten numbers between 9 to 21
(Use While-Loop).
46
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 15: write a java program to print out ten numbers between 9 to 21
(Use For-Loop).
47
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 16: write a java program to find the square root ofQuestion 16: write a java program to find the square root of
the number between 20 and 40 (Use scanner class)the number between 20 and 40 (Use scanner class)
import static java.lang.Math.*;
double sq = Math.sqrt(25)double sq = Math.sqrt(25)
48
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
49
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 17: write a java program to print out odd and even numbers between
1500 to -2000 (Use While-Loop).
1500: Even
1499: Odd
1498: Even
1497: Odd
-1999: Odd
-2000: Even
50
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 18: write a java program to print out positive and negative numbers
between -300 to 500 (Use While-Loop).
-300: Negative
-299: Negative
-298: Negative
-297: Negative
499: Positive
500: Positive
51
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
52
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 19: write a java program to print out sum and average of negative
numbers between 500 to -500 (Use For-Loop).
500
499
498
-499
-500 sum=? And ava=?
53
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
54
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 20: Write a java program to find out largest and sum of these
numbers  (0, 1, 2, 3, 4, 5, 6, 8,  100). (Use For-Loop)
55
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
56
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 21: Write a java program to print out five random characters
(Use For-Loop)
57
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Question 22: Write a java program to print out following star patterns in
console. (Use For-Loop)
58
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
59
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
60
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
23: Write a java program to print out A-Z characters with converting them
to their integer numbers. (Use For-Loop)
61
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
Q 24: write a java program to print out odd and even numbers between
1.01 to 99.99 (Use For-Loop).
1.01: Even
2.02: Odd
3.03: Even
97.97: Odd
98.98: Odd
99.99: Even
0
10
20
30
40
50
60
70
200
B[0]
B[1]
B[2]
B[3]
B[4]
B[5]
B[6]
B[7]
B[20]
Input output
0
1
2
3
4
5
6
7
20
process
Question 25: write a java program to print out the following arrays.
Sum
210
62
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
0
10
20
30
40
50
60
70
200
B[0]
B[1]
B[2]
B[3]
B[4]
B[5]
B[6]
B[7]
B[20]
Input output
0
- 10
- 20
- 30
- 40
- 50
- 60
- 70
- 20
process
Question 26:Question 26: write a java program to print out the following arrays.write a java program to print out the following arrays.
Sum
-2100
63
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
64
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
H1: write a java program to greet your friend. (Use Scanner)
If time is less than 10:00, create a "Good morning" greeting, if not,
but time is less than 20:00, create a "Good day" greeting, otherwise
a "Good evening":
H2: Write a Java program to print the number entered by user only
if the number entered is negative.
H3: Write a Java program to relate two integers entered by user
using = or > or < sign.
H4: Write a java program to find the sum of first n natural numbers
where n is entered by user. Note: 1,2,3... are called natural
numbers.
65
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
H5: Write a Java program to find the factorial of a number, where
the number is entered by user. (Hints: factorial of n = 1*2*3*...*n
H6: Write a Java program to add all the numbers entered by a user
until user enters 0. (Use Do – While Loop)
H7: Write a program that asks user an arithmetic
operator('+','-','*' or '/') and two operands and perform the
corresponding calculation on the operands.
H8: Write a program to print following output using for loop.
1
22
333
4444
55555
66
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
H9: write a java program to print out the sum of odd numbers
between - 3000 to -1000 (Use While-Loop).
-3000
-2990
-2980
…
-1000
67
© University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
END…END…
Any questions..?Any questions..?
Hope you have been happyHope you have been happy
Thank youThank you
By: Msc. Karwan M. KareemBy: Msc. Karwan M. Kareem
2014 - 20152014 - 2015

More Related Content

Similar to Java programming: Elementary practice

Reshma Kodwani , BCA Third Year
Reshma Kodwani , BCA Third YearReshma Kodwani , BCA Third Year
Reshma Kodwani , BCA Third Yeardezyneecole
 
_var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1...
_var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1..._var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1...
_var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1...Ioan Tuns
 
_var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1...
_var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1..._var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1...
_var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1...Ioan Tuns
 
Report summer training core java
Report summer training core javaReport summer training core java
Report summer training core javaSudhanshuVijay3
 
CSE215_Module_02_Elementary_Programming.ppt
CSE215_Module_02_Elementary_Programming.pptCSE215_Module_02_Elementary_Programming.ppt
CSE215_Module_02_Elementary_Programming.pptRashedurRahman18
 
66781291 java-lab-manual
66781291 java-lab-manual66781291 java-lab-manual
66781291 java-lab-manualLaura Popovici
 
4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdfamitbhachne
 
Primitive Data Types and Operations
Primitive Data Types and OperationsPrimitive Data Types and Operations
Primitive Data Types and Operationsnaimanighat
 
Pankajkumar1- B.Tech(CSE) 2015 Batch
Pankajkumar1- B.Tech(CSE) 2015 BatchPankajkumar1- B.Tech(CSE) 2015 Batch
Pankajkumar1- B.Tech(CSE) 2015 Batchpankaj kumar
 
Vikeshp
VikeshpVikeshp
VikeshpMdAsu1
 
Online_Examination
Online_ExaminationOnline_Examination
Online_ExaminationRupam Dey
 
Cs141 mid termexam2_v1answer
Cs141 mid termexam2_v1answerCs141 mid termexam2_v1answer
Cs141 mid termexam2_v1answerFahadaio
 
02slidLarge value of face area Large value of face area
02slidLarge value of face area Large value of face area02slidLarge value of face area Large value of face area
02slidLarge value of face area Large value of face areaAhmadHashlamon
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction onessuser656672
 
Neel training report
Neel training reportNeel training report
Neel training reportNeel Chandra
 
Online Examination Java Projectreport.docx
Online Examination Java Projectreport.docxOnline Examination Java Projectreport.docx
Online Examination Java Projectreport.docxTanishaPatil4
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Chapter 1_Intro to Java.ppt
Chapter 1_Intro to Java.pptChapter 1_Intro to Java.ppt
Chapter 1_Intro to Java.pptLisaMalar
 

Similar to Java programming: Elementary practice (20)

Reshma Kodwani , BCA Third Year
Reshma Kodwani , BCA Third YearReshma Kodwani , BCA Third Year
Reshma Kodwani , BCA Third Year
 
_var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1...
_var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1..._var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1...
_var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1...
 
_var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1...
_var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1..._var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1...
_var_www_moodledata_temp_turnitintooltwo_1014058337._Ioan_Tuns-HNDCSD-PJ-19-1...
 
Report summer training core java
Report summer training core javaReport summer training core java
Report summer training core java
 
CSE215_Module_02_Elementary_Programming.ppt
CSE215_Module_02_Elementary_Programming.pptCSE215_Module_02_Elementary_Programming.ppt
CSE215_Module_02_Elementary_Programming.ppt
 
66781291 java-lab-manual
66781291 java-lab-manual66781291 java-lab-manual
66781291 java-lab-manual
 
4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf
 
Primitive Data Types and Operations
Primitive Data Types and OperationsPrimitive Data Types and Operations
Primitive Data Types and Operations
 
Pankajkumar1- B.Tech(CSE) 2015 Batch
Pankajkumar1- B.Tech(CSE) 2015 BatchPankajkumar1- B.Tech(CSE) 2015 Batch
Pankajkumar1- B.Tech(CSE) 2015 Batch
 
Vikeshp
VikeshpVikeshp
Vikeshp
 
Industrial Training report on java
Industrial  Training report on javaIndustrial  Training report on java
Industrial Training report on java
 
Online_Examination
Online_ExaminationOnline_Examination
Online_Examination
 
Cs141 mid termexam2_v1answer
Cs141 mid termexam2_v1answerCs141 mid termexam2_v1answer
Cs141 mid termexam2_v1answer
 
02slidLarge value of face area Large value of face area
02slidLarge value of face area Large value of face area02slidLarge value of face area Large value of face area
02slidLarge value of face area Large value of face area
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one
 
Neel training report
Neel training reportNeel training report
Neel training report
 
Online Examination Java Projectreport.docx
Online Examination Java Projectreport.docxOnline Examination Java Projectreport.docx
Online Examination Java Projectreport.docx
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
coa.ppt
coa.pptcoa.ppt
coa.ppt
 
Chapter 1_Intro to Java.ppt
Chapter 1_Intro to Java.pptChapter 1_Intro to Java.ppt
Chapter 1_Intro to Java.ppt
 

Recently uploaded

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
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
 
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
 
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
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
[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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
[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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

Java programming: Elementary practice

  • 1. Structure programmingStructure programming Java Programming – PracticeJava Programming – Practice part -1part -1 Faculty of Physical and Basic Education Computer Science By: Msc. Karwan M. Kareem www.karwanit.com karwan@karwanit.com 2016 - 2017 1 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 2. Installing JDKInstalling JDK 1- go to JDK folder 2- Right click on JDK icon and click open 2 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 3. 3- Waiting for configuring the installer .. 3 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 4. 4- click on next button.. 4 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 5. 5- choose the installation folder.. 6 – click on next button … 5 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 6. 7 – click on Install button … 6 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 7. 8 – Waiting for installing all JDK files… 7 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 8. 8 – Installation completed successfully and click on finish button to finish the JDK… 8 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 9. 1- Click on the Eclipse – Shortcut or Eclipse -Icon 2- Choose a workspace folder to use for this session 3- Click ok Starting to write first Java program .... 9 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 10. 4- go to file list  new Java project 5- write your project name 10 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 11. 6- click next button 7- click finish 11 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 12. 8- go to the project  right click new  class 9- write name for your class 10- choose the modifier “public” 12 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 13. 11- choose the method 12- click finish 13 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 14. 13- write your Java Program 14- click on run and get the result 14 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 15. 1- Input: Define all variables 1- process 1- Output: print results Example: Write a Java program to calculate two numbersExample: Write a Java program to calculate two numbers 15 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 16. Example: Write a Java program to compute the area of the circle 1- allocate memory for radius 2- allocate memory for area 3- compute area and assign it to variable area 4- print a message to the console 16 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 17. Write a Java program to compute the area of the circle ( use JOptionPane)
  • 18. Example: Write a Java program to print out full name, with use theExample: Write a Java program to print out full name, with use the scanner classscanner class to handle input from a user.to handle input from a user. import java.util.Scanner;import java.util.Scanner; public class FullName {public class FullName { public static void main(String[] args) {public static void main(String[] args) { // TODO Auto-generated method stub// TODO Auto-generated method stub Scanner In = new Scanner (System.Scanner In = new Scanner (System.in);in); System.System.out.println("enter first name:");out.println("enter first name:"); String first_name = In.next();String first_name = In.next(); System.System.out.println("enter last name");out.println("enter last name"); String last_name=In.next();String last_name=In.next(); System.System.out.println("Your full name is: " + first_name +" "+ last_name);out.println("Your full name is: " + first_name +" "+ last_name); } }} } Create new Scanner Object Read first input Read second input 18 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 19. Example: Write a Java program to print out your profile,Example: Write a Java program to print out your profile, with use thewith use the scanner classscanner class to handle input from a userto handle input from a user import java.util.Scanner; public class FullName { public static void main(String[] args) { // TODO Auto-generated method stub Scanner In = new Scanner (System.in); System.out.println("enter first name:"); String first_name = In.next(); System.out.println("enter last name "); String last_name=In.next(); System.out.println("enter your age "); int age=In.nextInt(); System.out.println("enter your adress "); String address=In.next(); System.out.println("enter your gender "); String gender=In.next(); System.out.println("Your full name is: " + first_name + " " + last_name); System.out.println("Your age is: " + age); System.out.println("Your address: " + address); System.out.println("Your gender is: " + gender); } } Create new Scanner Object Read data from consol Print all variables 19 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 20. Example: Write a program that obtains Current Date & Time This is very easy to get current date and time in Java. You can use a simple Date object with toString() method to print current date and time as follows: import java.util.Date; public class DateDemo { public static void main(String args[]) { // Instantiate a Date object Date date = new Date(); // display time and date using toString() System.out.println(date.toString()); } } Create new Date Object Using toString to print current date and time 20 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 21. ) 94 (9 ))(5(10 5 43 y x xx cbayx + ++ ++− − + Example: Write a JAVA program to find out the output of theExample: Write a JAVA program to find out the output of the following rulesfollowing rules import java.util.Scanner; public class arth { public static void main(String[] args) { Scanner In = new Scanner (System.in); System.out.println("enter number a "); int a=In.nextInt(); System.out.println("enter number b "); int b=In.nextInt(); System.out.println("enter number c "); int c=In.nextInt(); System.out.println("enter number x "); int x=In.nextInt(); System.out.println("enter number y "); int y=In.nextInt(); double outPut = (3 + 4 * x) / 5 - (10 * (y-5)*(a+b+c))/x +9*(4/x+(9+x/y)); System.out.println("the result is :" + outPut); } } Create new Scanner Object Read data from consol 21 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 22. Question 1: Write a Java program to compute the area of the Trapezium, with use the scanner class to handle input from a user, and JOptionPane to print the result. 22 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 23. Question 2:AQuestion 2:A: Write a Java program to compute the area of the: Write a Java program to compute the area of the SectorSector,, with use thewith use the scanner classscanner class to handle input from a user,to handle input from a user, andand JOptionPaneJOptionPane to print the result.to print the result. 23 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 24. Question 2:BQuestion 2:B: Write a Java program to compute the area of the: Write a Java program to compute the area of the top part of the circle,top part of the circle, with use thewith use the JOptionPaneJOptionPane to handle inputto handle input from a user, andfrom a user, and consoleconsole to print the result.to print the result. 24 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015 1 2 3 4 5 6
  • 25. 25 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 26. Question 3Question 3: Write a Java program to compute the area of the: Write a Java program to compute the area of the EllipseEllipse,, with use thewith use the scanner classscanner class to handle input from a user,to handle input from a user, andand JOptionPaneJOptionPane to print the result.to print the result. 26 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 27. Question 4:A:Question 4:A: Write a JAVA program to find the real valueWrite a JAVA program to find the real value output of the following rules.output of the following rules. - UseUse Scanner classScanner class to handle input from a user.to handle input from a user. - UseUse JOptionPaneJOptionPane to print the result.to print the result. ) 4 (9 ))(5(10 5 4 h L LL cbahL y ++ ++− −= m h k dk hk b +++ − −= 4)5(11 5 15 27 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 28. 28 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015 Question 4:B:Question 4:B: Write a JAVA program to find the “real value” output of theWrite a JAVA program to find the “real value” output of the following rules.following rules. - UseUse Scanner classScanner class to handle input from a user.to handle input from a user. - UseUse JOptionPaneJOptionPane to print the result.to print the result. 10 10 23 −++= h x L xx y
  • 29. Question 5:Question 5: Write a Java program to print out your profile,Write a Java program to print out your profile, with use thewith use the scanner classscanner class to handle input from a userto handle input from a user outputoutput Name: Karwan M. KareemName: Karwan M. Kareem Gender: MaleGender: Male Age: 30Age: 30 Email address: mailExample@yahoo.comEmail address: mailExample@yahoo.com Address: SulAddress: Sul Note: any thingNote: any thing 29 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 30. Question 6: Write a java program to find theQuestion 6: Write a java program to find the SumSum andand AverageAverage of five lessons, and print them out with yourof five lessons, and print them out with your name. is he/ she good or bad student (Use JOptionPane forname. is he/ she good or bad student (Use JOptionPane for Input)Input) OUTPUT :OUTPUT : Your name : Karwan M. KareemYour name : Karwan M. Kareem Lessons1=55Lessons1=55 Lessons2=55Lessons2=55 Lessons3=55Lessons3=55 Lessons4=55Lessons4=55 Lessons5=55Lessons5=55 The sum = 275The sum = 275 The average = 55The average = 55 He is goodHe is good 30 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 31. 31 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 32. Question 7: Write a Java program to compare three numbersQuestion 7: Write a Java program to compare three numbers and find largest out of three (Use JOptionPane or Scanner).and find largest out of three (Use JOptionPane or Scanner). X greater then y and x greater then zX greater then y and x greater then z  "First number is largest""First number is largest" Y greater then x and y greater then zY greater then x and y greater then z  "Second number is largest""Second number is largest" zz greater thengreater then xx andand zz greater thengreater then yy  "Third number is largest""Third number is largest" ElseElse  "Entered numbers are equals...""Entered numbers are equals..." 32 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 33. 33 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 34. Question 8: write the program in Java aboutQuestion 8: write the program in Java about if elseif else the programthe program should ask the user to enter the total marks out of 100, and thenshould ask the user to enter the total marks out of 100, and then display the letter grade on the screen (Use Scanner class)display the letter grade on the screen (Use Scanner class) * Grade Rules:* Grade Rules: 0-490-49  D gradD grad 50-5550-55  C gradC grad 56-6056-60  C+ gradC+ grad 61-7061-70  B gradB grad 71-7571-75  B+ gradB+ grad 76-8576-85  A gradA grad 86-10086-100  A+ gradA+ grad Else “you have error …”Else “you have error …” 34 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 35. 35 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 36. 36 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 37. Question 9: Write a java program to implement a Vote System, with use JOptionPane for input and console for outpt Name : karwan kareem address: Sul / Hilan City gender: Male age: 30 Age > 0 and age <18 print  “cannot vote” age > 18 and age < 100 print  “can vote “ else print “you have error ” 37 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 38. 38 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 39. Question 10: Write a java program about “Good student “ (use JOptionPane) If gender is male and grade is 70 and above: display “Good boy" If gender is female and grade is 70 above: display “Good girl" but if grade is below 70 regardless of gender: display “Bad child" 39 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 40.
  • 41. Question 11: write a java program to create “size-system” (Use JOptionPane). If size equal to 1  X-small If size equal to 2  small If size equal to 3  Medium If size equal to 4  large If size equal to 5  X-large 41 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 42. 42 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 43. Question 12: write the output of the following Java codes. 43 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 44. Question 13: write the output of the following Java codes. 44 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 45. Question 13:B: write the output of the following Java codes. 45 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 46. Question 14: write a java program to print out ten numbers between 9 to 21 (Use While-Loop). 46 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 47. Question 15: write a java program to print out ten numbers between 9 to 21 (Use For-Loop). 47 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 48. Question 16: write a java program to find the square root ofQuestion 16: write a java program to find the square root of the number between 20 and 40 (Use scanner class)the number between 20 and 40 (Use scanner class) import static java.lang.Math.*; double sq = Math.sqrt(25)double sq = Math.sqrt(25) 48 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 49. 49 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 50. Question 17: write a java program to print out odd and even numbers between 1500 to -2000 (Use While-Loop). 1500: Even 1499: Odd 1498: Even 1497: Odd -1999: Odd -2000: Even 50 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 51. Question 18: write a java program to print out positive and negative numbers between -300 to 500 (Use While-Loop). -300: Negative -299: Negative -298: Negative -297: Negative 499: Positive 500: Positive 51 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 52. 52 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 53. Question 19: write a java program to print out sum and average of negative numbers between 500 to -500 (Use For-Loop). 500 499 498 -499 -500 sum=? And ava=? 53 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 54. 54 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 55. Question 20: Write a java program to find out largest and sum of these numbers  (0, 1, 2, 3, 4, 5, 6, 8,  100). (Use For-Loop) 55 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 56. 56 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 57. Question 21: Write a java program to print out five random characters (Use For-Loop) 57 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 58. Question 22: Write a java program to print out following star patterns in console. (Use For-Loop) 58 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 59. 59 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 60. 60 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015 23: Write a java program to print out A-Z characters with converting them to their integer numbers. (Use For-Loop)
  • 61. 61 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015 Q 24: write a java program to print out odd and even numbers between 1.01 to 99.99 (Use For-Loop). 1.01: Even 2.02: Odd 3.03: Even 97.97: Odd 98.98: Odd 99.99: Even
  • 62. 0 10 20 30 40 50 60 70 200 B[0] B[1] B[2] B[3] B[4] B[5] B[6] B[7] B[20] Input output 0 1 2 3 4 5 6 7 20 process Question 25: write a java program to print out the following arrays. Sum 210 62 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 63. 0 10 20 30 40 50 60 70 200 B[0] B[1] B[2] B[3] B[4] B[5] B[6] B[7] B[20] Input output 0 - 10 - 20 - 30 - 40 - 50 - 60 - 70 - 20 process Question 26:Question 26: write a java program to print out the following arrays.write a java program to print out the following arrays. Sum -2100 63 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015
  • 64. 64 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015 H1: write a java program to greet your friend. (Use Scanner) If time is less than 10:00, create a "Good morning" greeting, if not, but time is less than 20:00, create a "Good day" greeting, otherwise a "Good evening": H2: Write a Java program to print the number entered by user only if the number entered is negative. H3: Write a Java program to relate two integers entered by user using = or > or < sign. H4: Write a java program to find the sum of first n natural numbers where n is entered by user. Note: 1,2,3... are called natural numbers.
  • 65. 65 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015 H5: Write a Java program to find the factorial of a number, where the number is entered by user. (Hints: factorial of n = 1*2*3*...*n H6: Write a Java program to add all the numbers entered by a user until user enters 0. (Use Do – While Loop) H7: Write a program that asks user an arithmetic operator('+','-','*' or '/') and two operands and perform the corresponding calculation on the operands. H8: Write a program to print following output using for loop. 1 22 333 4444 55555
  • 66. 66 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015 H9: write a java program to print out the sum of odd numbers between - 3000 to -1000 (Use While-Loop). -3000 -2990 -2980 … -1000
  • 67. 67 © University of Sulaimani, Faculty of Physical & Basic Education, Department of Computer Science 2014 / 2015 END…END… Any questions..?Any questions..? Hope you have been happyHope you have been happy Thank youThank you By: Msc. Karwan M. KareemBy: Msc. Karwan M. Kareem 2014 - 20152014 - 2015