Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method named showChar. The method should accept two arguments: a referen

ID: 3675725 • Letter: W

Question

Write a method named showChar. The method should accept two arguments: a reference to a String object and an integer. The integer argument is a character position within the String, with the first character being a position 0. When the method executes, it should display the characters at the character position. Here is an example of a call to the method:

showChar('New York", 2);

In this call, the method will display the character w beause it is in position 2. Demonstrate the method in a complete program.

Explanation / Answer

class showchar
{
   public static char showChar(String s, int n)
   {
       return s.charAt(n);
   }

   public static void main(String args[])
   {
       char c=showChar("New York",2);

       System.out.println(c);
   }
}
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote