Strings and Arrays in Java
Path to Expertness
Join Date: Dec 2006
Posts: 0 Strings and Arrays in java
I have got some programming problems to solve and I would be grateful if someone could some them for me. I could compile some of them but doesn't give the result expected. The question goes as follows;
1). A String called testString contains an unknown number of numeric characters, letters and spaces. Write a loop that counts the number of spaces in testString, and puts the value into an already declared variable count.
2). A method called test has a signature;
public static String test(String testString, int n)
Write the method body, i.e. the sequence of lines that returns the last 'n' characters of testString as a String, converted to UpperCase.
3). A method caled test has a signature:
public static ArrayList<String> test(ArrayList<String> testAL)
The first three items in the ArraysList are the three String "One", "Two", and "Three". Write the body method as a sequence of lines of code that make its first three items the String "One", "Four", "Nine" and then returns the arraylist.
4). A password checking method called testPosition has a signature:
public static int testPosition(ArrayList<String> pins, String pin)
The method checks the String pin against each of the items in the ArrayList pins, and if it finds a match it returns its position in the ArrayList as an int, otherwise it returns the "rogue" (i.e. warning0 value: -1. Create a method.
5). A password checking method called testPins has a signature:
public static boolean testPins (ArrayList<String> pins, String pin)
The method checks the String pin against each of the items in the ArrayList pins, and if it finds a match it returns true, otherwise it prints the unmatched ArrayList item to the terminal window. Create the method.
6). A password checking method called testBlank has a signature:
public static boolean testBlank(ArrayList<String> passwords)
The method check each of the String in the ArrayList password and if it finds a blank, i.e. an empty String " ", it counts it. At the end of the check it returns the number of blank password in the ArrayList. Create the method.
7). Two String local variable are defined by the lines
String text = "some text";
String s = " ";
Write the code that will make 's' equal to the ROTATED right one character (with the last character being put at the beginning) e.g. if text was "abcdefgh" then 's' becomes
"habcdefg" or if text was binary string "01110011" then 's' becomes "10111001" Then use System.out.println() to print 's' to the terminal window
## I would be grateful if anyone could help me solve these java programs. Thank you.
|All times are GMT +5.5. The time now is 23:58.|