130 likes | 292 Views
Extra Examples. Duaa al-Saeed 14 Jun 2010. EX1. Write a program that reads two integers and then calls a method that receives the two integers and returns their greatest common divisor , which is printed in main. EX2.
E N D
Extra Examples Duaa al-Saeed 14 Jun 2010
EX1 • Write a program that reads two integers and then calls a method that receives the two integers and returns their greatest common divisor, which is printed in main..
EX2 • Write a program which calls a method named isMultiple. This method takes two integers values and determines whether the second integer is a multiple of the first. Main then prints an appropriate message. Sample run: Enter first number: 4Enter second number: 1616 is multiple of 4
EX3 • Write a program that reads an integer x and calls a method divisors that prints all the divisors of x. Sample run: Enter an integer: 8 The divisors of 8: 1 2 4 8
EX4 • Write a program that prompts the user to input an integer and then calls a method printDigits that receives the integer and outputs the individual digits of the number. Sample run: Enter an integer: 456 The individual digits of 456 are: 4 5 6
EX5 • Write a program that reads two integers n and m then calls a method PrinTablethat prints first (m) elements in the multiplication table of the integer n. Sample run: Enter two integers: 2 5 The first 5 elements in the multiplication table of 2 are : 2 x 1 = 2 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10
EX6 • Write a program with a method rnd1that receives a real number; and returns the number rounded to the nearest integer. And another method rnd2 that received a real number; and returns the number rounded to the nearest integer. rnd1 method should use the method Math.ceil, while rnd uses method Math.floor , main should read the real number from user and calls the two methods and print the 2 resulting integers.