Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.exercise;
- public class Main {
- public static void main(String[] args) {
- Methods methods = new Methods();
- System.out.print("Type a word: ");
- methods.setFirstWord();
- System.out.print("Type a second word: ");
- methods.setSecondWord();
- System.out.print("Length of the end part: ");
- methods.setCout();
- System.out.println("Result: "+ methods.getFirstWord().substring(0,methods.getCount()));
- System.out.println("--------------------------");
- System.out.println("Length of the end part: " + methods.getFirstWord().substring(methods.getEndPartFirstWord(),methods.getFirstWordLength()));
- System.out.println("--------------------------");
- if (!(methods.getSecondWordIndex() ==-1)){
- System.out.println("The word " + methods.getSecondWord() + " is found in the word " + methods.getFirstWord());
- }else{
- System.out.println("The word " + methods.getSecondWord() + " isn't found in the word " + methods.getFirstWord());
- }
- System.out.println("--------------------------");
- for (int i=methods.getFirstWord().length(); i<=methods.getFirstWord().length();i--){
- try{System.out.print(methods.getFirstWord().charAt(i-1));}
- catch (StringIndexOutOfBoundsException e){}
- if (i==0){
- break;
- }
- }
- }
- }
- package pl.exercise;
- import java.util.Scanner;
- public class Methods {
- private String firstWord = "";
- private String secondWord = "";
- private int count = 0;
- Scanner scanner = new Scanner(System.in);
- public String getFirstWord() {
- return firstWord;
- }
- public void setFirstWord() {
- firstWord=scanner.nextLine();
- }
- public int getEndPartFirstWord() {
- int value=firstWord.length()-getCount();
- return value;
- }
- public int getFirstWordLength() {
- return firstWord.length();
- }
- public String getSecondWord() {
- return secondWord;
- }
- public int getSecondWordIndex() {
- int index = getFirstWord().indexOf(getSecondWord());
- return index;
- }
- public void setSecondWord() {
- secondWord=scanner.nextLine();
- }
- public int getCount() {
- return count;
- }
- public void setCout() {
- count =scanner.nextByte();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement