Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help in Java, please my code is finished but I can't figure out why my code is not working, the error I get is java:

Help in Java, please

my code is finished but I can't figure out why my code is not working, the error I get is java: variable q might not have been initialized

package cpsc2150.MyDeque; import java.sql.Array; import java.util.*; public class DequeApp { public static void main(String[] args) { IDeque q; int uI = 0; System.out.println("Enter 1 for array implementation or 2 for List implementation"); Scanner sc = new Scanner(System.in); uI = sc.nextInt(); while (uI < 1 || uI > 2) { System.out.println("Invalid number. Please enter 1 for array implementation or 2 for List implementation"); uI = sc.nextInt(); } if(uI == 1) { //q turns into an array //System.out.println("yes"); q = new ArrayDeque(); } if (uI == 2) { //q turns into a list //System.out.println("no"); q = new ListDeque(); } Integer x = 3; q.enqueue(x); x = -8; q.enqueue(x); x = 15; q.enqueue(x); x = 0; q.enqueue(x); x = -4; q.enqueue(x); System.out.println(q); sc.close(); } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions