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

For JAVA, using Scanner.in., how would you write a method named showChar. The me

ID: 3634835 • Letter: F

Question

For JAVA, using Scanner.in., how would you 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 at position 0. When the method executes, it should display the character at that 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 because it is in position 2. Demonstrate the method in a complete program.

Explanation / Answer

Please Rate:Thanks

import java.util.Scanner;
public class hw
{

public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println ("Give me a string");
String str = keyboard.nextLine();
System.out.println ("and a position");
int num = keyboard.nextInt();
ShowChar ( str, num);
}

public static void ShowChar (String word, int number)

{
System.out.println ("the character at position " +
number + " of the string " + word+ " is " + word.charAt(number));

}
}

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

Give me a string
India
and a position
3
the character at position 3 of the string India is i
BUILD SUCCESSFUL (total time: 11 seconds)

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