Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package TextProcessing;
- import java.util.Locale;
- import java.util.Scanner;
- public class Demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String name = "Desi"; //['D', 'e', 's', 'i']
- String lastName = scanner.nextLine();
- System.out.println(name.charAt(0)); //първа буква: 'D'
- System.out.println(name.charAt(name.length() - 1)); //последна буква: 'i'
- System.out.println(name.length()); //брой на символи = 4
- System.out.println(name.toUpperCase()); //DESI
- System.out.println(name.toLowerCase()); //desi
- System.out.println(name.equals(lastName)); //false
- System.out.println(name.equals("Desi")); //true
- //true -> двата текста са еднакви
- //false -> двата текста не са еднакви
- char [] symbols = name.toCharArray(); //['D', 'e', 's', 'i']
- System.out.println(name + " " + lastName); //str + str + str = str (конкатенация)
- System.out.println(name + 12); //str + int = str
- System.out.println(name + 34.5); //str + double = str
- String sentence = "The cat is under the table";
- sentence = sentence.replaceAll(" ", "_");
- System.out.println(sentence); //"The_cat_is_under_the_table"
- String firstWord = sentence.substring(0, 3);
- System.out.println(firstWord); //The
- String lastWord = sentence.substring(21);
- System.out.println(lastWord); //table
- System.out.println(sentence.contains("under")); //true
- System.out.println(sentence.contains("dog")); //false
- //true -> в текста имаме дадената дума
- //false -> в текста нямаме дадената дума
- String[] words = sentence.split("_"); //["The", "cat", "is", "under", "the", "table"]
- System.out.println(sentence.indexOf('u'));//11
- System.out.println(sentence.lastIndexOf('e')); //25
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment