Click here to load reader

Extra Examples

  • Upload
    hyman

  • View
    41

  • Download
    0

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

Citation preview

Extra Examples

Duaa al-Saeed

14 Jun 2010

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

EX2Write 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

EX3Write a program that reads an integer x and calls a method divisors that prints all the divisors of x.

Sample run:Enter an integer: 8The 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: 456The individual digits of 456 are: 4 5 6

EX5Write a program that reads two integers n and m then calls a method PrinTable that prints first (m) elements in the multiplication table of the integer n. Sample run:Enter two integers: 2 5The first 5 elements in the multiplication table of 2 are : 2 x 1 = 22 x 2 = 42 x 3 = 62 x 4 = 82 x 5 = 10

EX6 Write a program with a method rnd1 that 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.