import java.util.
*;
class StartsEnds {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string:");
String s = sc.nextLine();
System.out.println("Starts with 'A'? " + s.startsWith("A"));
System.out.println("Ends with 'Z'? " + s.endsWith("Z"));
}
}
import java.util.*;
class CompareWords {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter first word:");
String w1 = sc.nextLine();
System.out.println("Enter second word:");
String w2 = sc.nextLine();
int res = w1.compareTo(w2);
if (res == 0)
System.out.println("Both words are equal.");
else if (res < 0)
System.out.println(w1 + " comes before " + w2);
else
System.out.println(w1 + " comes after " + w2);
}
}
import java.util.*;
class LongestWord {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence:");
String s = sc.nextLine() + " ";
String word = "", maxWord = "";
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (ch != ' ')
word += ch;
else {
if (word.length() > maxWord.length())
maxWord = word;
word = "";
}
}
System.out.println("Longest word: " + maxWord);
}
}
import java.util.*;
class PalindromeWords {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence:");
String s = sc.nextLine() + " ";
String word = "";
System.out.println("Palindrome words:");
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (ch != ' ')
word += ch;
else {
String rev = "";
for (int j = word.length() - 1; j >= 0; j--)
rev += word.charAt(j);
if (word.equalsIgnoreCase(rev))
System.out.println(word);
word = "";
}
}
}
}
import java.util.*;
class ReverseWords {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence:");
String s = sc.nextLine() + " ";
String word = "", result = "";
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (ch != ' ')
word += ch;
else {
result = word + " " + result;
word = "";
}
}
System.out.println("Reversed Sentence: " + result.trim());
}
}
import java.util.*;
class MostVowelWord {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence:");
String s = sc.nextLine() + " ";
s = s.toUpperCase();
String word = "", maxWord = "";
int vowelCount = 0, maxVowel = 0;
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (ch != ' ') {
word += ch;
if ("AEIOU".indexOf(ch) != -1)
vowelCount++;
} else {
if (vowelCount > maxVowel) {
maxVowel = vowelCount;
maxWord = word;
}
word = "";
vowelCount = 0;
}
}
System.out.println("Word with most vowels: " + maxWord);
}
}
import java.util.*;
class LongestWord {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence:");
String s = sc.nextLine() + " ";
String word = "", maxWord = "";
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
if (ch != ' ')
word += ch;
else {
if (word.length() > maxWord.length())
maxWord = word;
word = "";
}
}
System.out.println("Longest word: " + maxWord);
}
}