SHARE
TWEET

Untitled

a guest Jan 18th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Main {
  2.     public static void main(String[] args) {
  3.  
  4.         GetMethods getMethods = new GetMethods();
  5.  
  6.         writeName(getMethods);
  7.         System.out.println("Hello, " + getMethods.getName());
  8.         System.out.println("Length your name is: " + getMethods.getName().length());
  9.         System.out.println("First letter your name is: " + getMethods.getName().charAt(0));
  10.         System.out.println("Last letter your name is: " + getMethods.getName().charAt(getMethods.getName().length() - 1));
  11.         System.out.println("---------------------------------");
  12.  
  13.         writeName(getMethods);
  14.         System.out.println("Three first letters of name: "+getMethods.getName().substring(0,3));
  15.         System.out.println("---------------------------------");
  16.  
  17.         writeName(getMethods);
  18.         for (int i=0; i<getMethods.getName().length();i++){
  19.             System.out.println(i + " character: "+getMethods.getName().charAt(i));
  20.         }
  21.         System.out.println("---------------------------------");
  22.  
  23.         writeName(getMethods);
  24.         for (int i=getMethods.getName().length(); i<=getMethods.getName().length();i--){
  25.  
  26.             try {
  27.                 System.out.print(getMethods.getName().charAt(i-1));
  28.             }catch (StringIndexOutOfBoundsException e){
  29.  
  30.             }
  31.  
  32.             if (i==0){
  33.                 break;
  34.             }
  35.  
  36.         }
  37.  
  38.     }
  39.  
  40.     private static void writeName(GetMethods getMethods) {
  41.         System.out.print("Write random name: ");
  42.         getMethods.setName();
  43.     }
  44. }
  45.  
  46.  
  47.  
  48. import java.util.Scanner;
  49.  
  50. public class GetMethods {
  51.  
  52.     private String name = "";
  53.  
  54.     Scanner scanner = new Scanner(System.in);
  55.  
  56.  
  57.     public String getName() {
  58.         return name;
  59.     }
  60.  
  61.     public void setName() {
  62.         name = scanner.nextLine();
  63.     }
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top