In Java language write a main method that calls each of thes

In Java language write a main method that calls each of these three methods.
(a) public static String reverse(String name)
reverse may assume without checking that the arg (e.g. \"John Smith\") is a first name consisting of >=1 letters and no non-letters,followed by a single space, followed by a last name consisting of >=1 letters and non-letters
reverse\'s job is to return the last- name-first version of the name:
the last name, followed by a comma, followed by a single space, followed by the first name
(b) public static int howMany (String little,String big);
howMany\'s job is to return how many times the string little appears in the string big. howMany may assume without checking that neither arg is the empty string, and that the occurrences of little in big don\'t overlap each other (case sensitive) . For example, howMany(\"na\", \"banananaNA\") returns 3
(c) public static String noSpace(String s);
noSpace\'s job is to return a String that is just like the arg, except with the spaces removed. For example,
noSpace(\"How now brown cow\")returns\" Hownowbrowncow\".

Solution

Main method for String reverse:

import java.util.*;

class ReverseString

{

public static void main(String args[ ])

{

String original, reverse = \"\";

Scanner in = new Scanner(System.in);

System.out.println(\"Enter a string to reverse\");

original = in.nextLine();

int length = original.length();

for( int i = length - 1; i >= 0; i-- )

reverse = reverse + original.charAt(i);

System.out.println(\"Reverse of entered string is: \"+reverse):

}

}

Main method for int how many:

public class IntArgsTest

{

public static void main (int[ ] args)

{

IntArgsTest iat = new IntArgsTest(args);

}

public IntArgsTest(int[ ] n)

{

System.out.println( n[0] );

}

public static void main (String[ ] args)

{

int[ ] intArgs = new int[args.length];

for ( int i : intArgs )

{

try {

intArgs[i] = Integer.parseInt(args[i]);

}

catch (NumberFormatException e)

{

System.err.println(\" Failed trying to parse a non-numeric argument, \" + args[i]);

}

}

main(intArgs);

}

}

Main method for String noSpace:

public static String removeSpace(String s)

{

String withoutspaces = \"\";

for (int i = 0; i < s.length(); i++)

{

if (s.charAt(i) != \' \')

withoutspaces += s.charAt(i);

}

return withoutspaces;

}

In Java language write a main method that calls each of these three methods. (a) public static String reverse(String name) reverse may assume without checking t
In Java language write a main method that calls each of these three methods. (a) public static String reverse(String name) reverse may assume without checking t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site