Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. //This program is for assignment #7 question #3
  2. import java.util.Scanner;
  3. public class ShowChar
  4. {
  5.   public static void main(String [] args)
  6.   {
  7.     Scanner s = new Scanner(System.in);
  8.     System.out.println("Please enter the String");
  9.     String input =s.nextLine();
  10.     System.out.println("Please enter the Character Position you would like to find from the string");
  11.     int pos =s.nextInt();
  12.     if (pos < 0 || pos > input.length)
  13.     System.out.println("Wrong number");
  14.     else if (pos != 0)
  15.     {
  16.         Char position = showChar(input,pos);
  17.         System.out.println(position);
  18.     }
  19.   }
  20.  
  21.   public static Char showChar(String name,int place)
  22.   {
  23.         place--;
  24.         char position = name.CharAt(place);
  25.         return position;
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement