Write a Java Program to Check if two of three boolean variables are true

Java Program to Check if two of three boolean variables are true

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Java Program to Check if two of three boolean variables are true
Java Program to Check if two of three boolean variables are true

Write a Java Program to Check if two of three boolean variables are true

PROGRAM: Java Program to Check if two of three boolean variables are true

/*Java Program to Check if two of three boolean variables are true*/

1: Remove element using remove()

import java.util.LinkedList;

class Main {
public static void main(String[] args) {
LinkedList<String> languages = new LinkedList<>();

// add elements in LinkedList
languages.add(“Java”);
languages.add(“Python”);
languages.add(“JavaScript”);
languages.add(“Kotlin”);
System.out.println(“LinkedList: ” + languages);

// remove elements from index 1
String str = languages.remove(3);
System.out.println(“Removed Element: ” + str);

System.out.println(“Updated LinkedList: ” + languages);
}
}

2 Using listIterator() Method

import java.util.ArrayList;
import java.util.ListIterator;

class Main {
public static void main(String[] args) {
ArrayList<String> animals= new ArrayList<>();

// add elements
animals.add(“Dog”);
animals.add(“Cat”);
animals.add(“Horse”);
System.out.println(“LinkedList: ” + animals);

// creating an object of ListIterator
ListIterator<String> listIterate = animals.listIterator();
listIterate.next();

// Remove element returned by next()
listIterate.remove();
System.out.println(“New LinkedList: ” + animals);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *