import java.util.
ArrayList;
public class SeparatePositiveNegative {
public static void main(String[] args) {
int[] arr = {-12, 11, -5, -7, -9, 6, -1, 5};
ArrayList<Integer> negative = new ArrayList<>();
ArrayList<Integer> positive = new ArrayList<>();
// Separate negative and positive numbers
for (int num : arr) {
if (num < 0) {
negative.add(num);
} else {
positive.add(num);
}
}
// Combine both lists into a single output array
negative.addAll(positive);
System.out.println(negative);
}
}
public class LongestWord {
public static void main(String[] args) {
String sentence = "The quick brown fox jumps over the lazy dog";
String[] words = sentence.split(" ");
String longestWord = "";
for (String word : words) {
if (word.length() > longestWord.length()) {
longestWord = word;
}
}
System.out.println("The longest word is: " + longestWord);
}
}
package predrive9;
import java.util.HashSet;
import java.util.Set;
public class PangramChecker {
public static void main(String[] args) {
String sentence = "The quick brown fox jumps over the lazy dog";
if (isPangram(sentence)) {
System.out.println("The sentence is a pangram.");
} else {
System.out.println("The sentence is not a pangram.");
}
}
public static boolean isPangram(String sentence) {
Set<Character> letters = new HashSet<>();
sentence = sentence.toLowerCase();
for (int i = 0; i < sentence.length(); i++) {
char c = sentence.charAt(i);
if (c >= 'a' && c <= 'z') {
letters.add(c);
}
}
return letters.size() == 26;
}
}
package predrive9;
public class PangramChecker {
public static void main(String[] args) {
String sentence = "The quick brown fox jumps over the lazy dog";
if (isPangram(sentence)) {
System.out.println("The sentence is a pangram.");
} else {
System.out.println("The sentence is not a pangram.");
}
}
public static boolean isPangram(String sentence) {
sentence = sentence.toLowerCase();
boolean[] letters = new boolean[26]; // Array to track each letter in the
alphabet
for (int i = 0; i < sentence.length(); i++) {
char c = sentence.charAt(i);
if (c >= 'a' && c <= 'z') {
letters[c - 'a'] = true; // Mark the corresponding letter as found
}
}
for (boolean found : letters) {
if (!found) {
return false; // If any letter is missing, it's not a pangram
}
}
return true; // All letters were found, so it's a pangram
}
}