Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.44 KB | None | 0 0
  1. package pl.exercise;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Methods methods = new Methods();
  8.  
  9.         System.out.print("Type a word: ");
  10.         methods.setFirstWord();
  11.         System.out.print("Type a second word: ");
  12.         methods.setSecondWord();
  13.         System.out.print("Length of the end part: ");
  14.         methods.setCout();
  15.         System.out.println("Result: "+ methods.getFirstWord().substring(0,methods.getCount()));
  16.         System.out.println("--------------------------");
  17.  
  18.         System.out.println("Length of the end part: " + methods.getFirstWord().substring(methods.getEndPartFirstWord(),methods.getFirstWordLength()));
  19.         System.out.println("--------------------------");
  20.  
  21.         if (!(methods.getSecondWordIndex() ==-1)){
  22.             System.out.println("The word " + methods.getSecondWord() + " is found in the word " + methods.getFirstWord());
  23.         }else{
  24.             System.out.println("The word " + methods.getSecondWord() + " isn't found in the word " + methods.getFirstWord());
  25.         }
  26.         System.out.println("--------------------------");
  27.  
  28.         for (int i=methods.getFirstWord().length(); i<=methods.getFirstWord().length();i--){
  29.  
  30.             try{System.out.print(methods.getFirstWord().charAt(i-1));}
  31.             catch (StringIndexOutOfBoundsException e){}
  32.  
  33.             if (i==0){
  34.                 break;
  35.             }
  36.  
  37.         }
  38.  
  39.  
  40.     }
  41.  
  42. }
  43.  
  44.  
  45. package pl.exercise;
  46.  
  47. import java.util.Scanner;
  48.  
  49. public class Methods {
  50.  
  51.     private String firstWord = "";
  52.     private String secondWord = "";
  53.     private int count = 0;
  54.  
  55.  
  56.  
  57.  
  58.  
  59.     Scanner scanner = new Scanner(System.in);
  60.  
  61.  
  62.  
  63.     public String getFirstWord() {
  64.         return firstWord;
  65.     }
  66.  
  67.     public void setFirstWord() {
  68.         firstWord=scanner.nextLine();
  69.     }
  70.  
  71.     public int getEndPartFirstWord() {
  72.         int value=firstWord.length()-getCount();
  73.         return value;
  74.     }
  75.  
  76.     public int getFirstWordLength() {
  77.         return firstWord.length();
  78.     }
  79.  
  80.     public String getSecondWord() {
  81.         return secondWord;
  82.     }
  83.  
  84.     public int getSecondWordIndex() {
  85.        int index = getFirstWord().indexOf(getSecondWord());
  86.         return index;
  87.     }
  88.  
  89.     public void setSecondWord() {
  90.         secondWord=scanner.nextLine();
  91.     }
  92.  
  93.     public int getCount() {
  94.         return count;
  95.     }
  96.  
  97.     public void setCout() {
  98.         count =scanner.nextByte();
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement