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

Directions from the book - Write a method named showChar . The method should acc

ID: 3761702 • Letter: D

Question

Directions from the book - Write a method named showChar. The method should accept two arguments; a reference to a Stringobject and an integer. The integer argument is a character position within the String, with the first character being at position 0. Here is an example of a call to the method:

showChar("New York", 2);

Name the class Lastname05a and save the file as Lastname05a.java. USE YOUR LAST NAME INSTEAD OF THE WORD LASTNAME.

Tell the user to enter the text for the String and an integer to determine which letter to display

Not only must your program meet the requirements of the problem,you must also:

You must ATTACH the .java file before submitting the assignment.

Explanation / Answer

import java.util.*;   
public class Lastname05a
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Please enter a city: ");
String city = keyboard.nextLine();
System.out.print("Enter the desired character location: ");
int y = keyboard.nextInt();
showChar( city, y );
}
public static void showChar( String city, int y )
{   
char x = city.charAt(y);
System.out.println("In " + city + " the character in location " +y + " is " + x);
}
}

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