Question: incompatible types: object cannot be converted to char on bolded line of code. Please help me figure out why. ------------------------------------------------------------------------------------------------------------------------------------------------------------------- package dequecharacters; import java.util.Deque; import
"incompatible types: object cannot be converted to char" on bolded line of code. Please help me figure out why.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
package dequecharacters;
import java.util.Deque; import java.util.ArrayDeque; import java.util.Scanner; public class DequeCharacters { public static void main(String[] args) { char ch; Deque chars1 = new ArrayDeque(); Scanner input = new Scanner(System.in); System.out.println("Enter a sequence of characters (end with a character 'Q' or q'):"); ch = input.next().charAt(0); while(ch != 'Q' && ch != 'q') { chars1.offerLast(ch); ch = input.next().charAt(0); }
System.out.println(" The characters entered in the first deque are: " + chars1);
Deque chars2 = new ArrayDeque();
while(!chars1.isEmpty()) { ch = chars1.removeLast(); // *****Incompatible type error here****** chars2.offerLast(ch); } System.out.println(" After moving the characters from the first deque to the second deque:"); System.out.println("The characters in the second deque are: "+ chars2); System.out.println("The characters in the first deque are: " + chars1); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
