Skip to content

Instantly share code, notes, and snippets.

@jacobtender
Created April 10, 2019 00:57
Show Gist options
  • Save jacobtender/b73c8c8a4207ffe6daf1562acb758419 to your computer and use it in GitHub Desktop.
Save jacobtender/b73c8c8a4207ffe6daf1562acb758419 to your computer and use it in GitHub Desktop.
Solved Source for: Method_showChar
/*
A showChar Method
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. The method does not return anything.
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.
*/
import java.util.Scanner;
public class Method_showChar
{
public static void showChar(String str, int index){
System.out.print(str.charAt(index));
}
public static void main(String[] args)
{
String input;
int index;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a line of text: ");
input = keyboard.nextLine();
System.out.print("Enter your index: ");
index = keyboard.nextInt();
showChar(input, index);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment