1 / 13

Extra Examples

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.

hyman
Download Presentation

Extra Examples

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Extra Examples Duaa al-Saeed 14 Jun 2010

  2. 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..

  3. 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

  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

  5. 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

  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

  7. 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.

More Related