Programming Fundamentals Assignment: Static Methods, Exercises of Java Programming

A programming assignment from the cs and it dept of superior university. The assignment involves writing and testing various static methods in java, including methods to calculate the area of a circle, find the smallest integer, raise a number to a power, determine if a number is a square, compute the cube of a number, get the kth digit of a number, calculate the factorial of a number, sum the elements of an array, reverse a string, reverse an integer, determine if a number is prime, return the nth fibonacci number, print numbers between given ranges, print even numbers between given ranges, print odd numbers between given ranges, and find the remainder of a division. The assignment is intended for university students studying computer science and it.

Typology: Exercises

2016/2017

Uploaded on 05/03/2017

noorafshan
noorafshan 🇵🇰

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Assignment of Arrays (Programming
Fundamentals)
Superior University
CS and IT Dept
1. Write and test the following static method that returns the area of a circle with
a given radius:
static oat calculateArea(oat r)
2. Write and test the following static method that returns the smallest of two
given integers:
static int min(int a, int b)
3. Write and test the following static method that uses the min( int , int ) method
of question No 2 to nd and return the smallest of three integers:
static int min( int a, int b, int c)
4. Write and test the following static method that uses the min( int, int, int)
method of question No 3 to nd the smallest of four integers:
static int min( int a, int b, int c, int d)
5. Write and test the following static method that returns X raised to power P,
where P can be any nonnegative integers:
static long power( int x, int p)
pf3
pf4

Partial preview of the text

Download Programming Fundamentals Assignment: Static Methods and more Exercises Java Programming in PDF only on Docsity!

Assignment of Arrays (Programming

Fundamentals)

Superior University

CS and IT Dept

  1. Write and test the following static method that returns the area of a circle with a given radius: static fl oat calculateArea( fl oat r) 2. Write and test the following static method that returns the smallest of two given integers: static int min(int a, int b) 3. Write and test the following static method that uses the min( int , int ) method of question No 2 to find and return the smallest of three integers: static int min( int a, int b, int c) 4. Write and test the following static method that uses the min( int, int, int) method of question No 3 to find the smallest of four integers: static int min( int a, int b, int c, int d) 5. Write and test the following static method that returns X raised to power P, where P can be any nonnegative integers: static long power( int x, int p)

6. Write and test the following static method that determines whether the given integer is a square number: static boolean isSquare(int n) ( Note: The first ten square numbers are 1,4,9,16,25,36,49,64,81 and 100. ) 7. Write and test the following static method that computes the cube of a given integer: static long cube( int n)

  1. Write and test the following static method that returns the kth digit of the positive integer n: static int getDigit( int n, int k). If n=29415 then the call getDigit(n,0) would return the digit 5, and the call getDigit(n,2) would return the digit 4. Not e that the digits are numbered from right to left, beginning with the ‘zeroth digit’. 9. Write and test the following static method using recursion that calculates and returns the factorial of an given integer: static int factorial(int n)
  2. Write and test the following static method using recursion that computes and returns the sum of the first “n” elements of an array “a[]”: Static int sumOfArray(int a[], int n)
  3. Write and test the following static method that returns the reverse of the string given. For example the method call reverse(“abcdef”) would return “fedcba”

17. Write and test the following static method using recursion that would print the series of ODD numbers between the given ranges (start and end). NOTE: Don’t use any loop syntax. static void printOdd( int start,int end ) 18. For some reason, the computer you're working on doesn't allow you to use the modulo operator % to compute the remainder of a division. Write and test the following static method using recursion that would return the remainder. For example the following call remainder (14, 3) would return 2 (14%3=2). static void remainder( int numerator ,int denominator )

  1. Write and test the following static method that returns the reverse of the array element provided. For example; int b[]={1,2,3,4,5}; b=reverseArray(b); will reverse the elements in array b. The result would be like: Before Reverse: 1,2,3,4,5, After Reverse: 5,4,3,2,1,

-------------------------------------------