daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 57 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.             if (i==0){
  31.                 break;
  32.             }
  33.  
  34.         }
  35.  
  36.     }
  37.  
  38.     private static void writeName(GetMethods getMethods) {
  39.         System.out.print("Write random name: ");
  40.         getMethods.setName();
  41.     }
  42. }
  43.  
  44.  
  45.  
  46. import java.util.Scanner;
  47.  
  48. public class GetMethods {
  49.  
  50.     private String name = "";
  51.  
  52.     Scanner scanner = new Scanner(System.in);
  53.  
  54.  
  55.     public String getName() {
  56.         return name;
  57.     }
  58.  
  59.     public void setName() {
  60.         name = scanner.nextLine();
  61.     }
  62. }
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