Document

University of Human Development
College of Science and Technology
Computer Science department/ Morning
Second Class 2014-2015
Review of java Practical2
Mazen Ismaeel Ghareb
http://mazinismaeel.org/
Chapter One
Practical one
 If you have N eggs, then you have N/12 dozen eggs, with N%12
eggs left over. (This is essentially the definition of the / and %
operators for integers.) Write a program that asks the user how
many eggs she has and then tells the user how many dozen eggs
she has and how many extra eggs are left over.

 A gross of eggs is equal to 144 eggs. Extend your program so
that it will tell the user how many gross, how many dozen, and
how many left over eggs she has. For example, if the user says
that she has 1342 eggs, then your program would respond with


Your number of eggs is 9 gross, 3 dozen, and 10
Procedure convert decimal number to
binary number
 We start with the given
decimal number, and
repeatedly divide it by 2
(whole number division
where the result will be
only the quotient, a whole
number) and note down
the remainder at every step
till we obtain the quotient
as 0 .
Practical Two
Write a program to convert decimal number to binary number
Enter a decimal string: 14
The equivalent number for binary is 11
Enter a decimal : “0101”
Error: Invalid decimal String “0101"
Practical Three
 Q/write a program to convert binary value to decimal in
Java ?
 run:
 Enter the Binary value: 1010
 Decimal:=10
Home Work
 Find duplicate Character in String “I’m Clever Student”
 The output is :
Home Work 2
What output is produced by the following program segment? Why? (Recall that name.charAt(i) is
the i-th character in the string, name.)

String name;

int i;

boolean startWord;












name = "Richard M. Nixon";
startWord = true;
for (i = 0; i < name.length(); i++) {
if (startWord)
System.out.println(name.charAt(i));
if (name.charAt(i) == ' ')
startWord = true;
else
startWord = false;
}