0% found this document useful (0 votes)
29 views1 page

Java Exercises

The document describes the signatures and examples for 7 different methods: 1. A method to compute the length of a non-negative integer. 2. A method to sort a non-negative integer. 3. A method to reverse a string. 4. A method to convert a word to pig latin by moving first consonants to end and adding "ay". 5. A method to check if two strings are anagrams. 6. A method to replace all spaces in a string with "%20". 7. A method to convert an integer between 0 to 999,999 to an English phrase.

Uploaded by

J.k. de Veyra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

Java Exercises

The document describes the signatures and examples for 7 different methods: 1. A method to compute the length of a non-negative integer. 2. A method to sort a non-negative integer. 3. A method to reverse a string. 4. A method to convert a word to pig latin by moving first consonants to end and adding "ay". 5. A method to check if two strings are anagrams. 6. A method to replace all spaces in a string with "%20". 7. A method to convert an integer between 0 to 999,999 to an English phrase.

Uploaded by

J.k. de Veyra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1. Write a method that will compute for the length of a non-negative number.

METHOD SIGNATURE

EXAMPLES INPUT OUTPUT

pig igpay

computer omputercay

chair airchay

apple appleay

public static int length(int input)

input a non-negative integer. returns the length of the input.


EXAMPLES INPUT OUTPUT

5. Write a method to decide if two strings are anagrams or not.


METHOD SIGNATURE

0 1

110 3

3210 4

public static boolean isAnagram( String a, String b)

returns true if anagram, false otherwise.


EXAMPLES INPUT OUTPUT

RULES

Arrays and Strings are not allowed. 2. Write a method that will sort a non-negative integer.
METHOD SIGNATURE

pig, gip
true

banana, potato
false

public static int sorted(int input)

6. Write a method to replace all spaces in a string with %20.


METHOD SIGNATURE

input - a non-negative integer. returns the sorted input.


EXAMPLES INPUT OUTPUT

public static String replace(String input)


EXAMPLES

0 0

110 11

321 123

INPUT OUTPUT

hello world hello%20world

RULES

Arrays and Strings are not allowed. 3. Write a method that reverses a string.
METHOD SIGNATURE

7. Given an integer between 0 and 999,999, return an English phrase that describes the integer.
METHOD SIGNATURE

public static String inWords(int input)

public static String stringRev(String input)


EXAMPLES INPUT OUTPUT RULES

EXAMPLES INPUT

100
"One Hundred"

1,234
"One Thousand, Two Hundred and Thirty Four"

a a

abc
cba

abc123 321cba

OUTPUT

Built-in method reverse() is forbidden to use. 4. Write a method that will convert a word to piglatin. A piglatin is formed by moving the first group of consonant to the end of a word and appeding ay.
METHOD SIGNATURE

public static String piglatin(String input)

You might also like