0

can any one please correct this code dont know the problem

/* package codechef; // don't place package name! */ import java.util.Scanner; /* Name of the class has to be "Main" only if the class is public. */ class Queue { int f = -1, r = -1; int n = 10; int q[] = new int[n]; void isFull() { if (r == (n - 1)) { System.out.print("Queue is full"); } else { Scanner sc = new Scanner(System.in); System.out.print("Enter Data"); int i = sc.nextInt(); if (f == -1 && r == -1) { f = 0; r = 0; q[r] = i; // contains the data that user will insert sc.close(); } else { r = r + 1; q[r] = i; } } } void isEmpty() { if (f == -1 && r == -1) { System.out.print("Queue is empty"); } else { f = f + 1; } } void display() { System.out.print("items are: "); for (int i = f; i <= r; i++) { System.out.println(q[i]); } } public static void main(String[] args) { int d; Scanner sc = new Scanner(System.in); Queue s = new Queue(); int l; do { System.out.print("Press 1 to Enqueue "); System.out.print("Press 2 to Dequeue "); System.out.print("Press 3 to Display "); System.out.print(" Enter your Choice "); d = sc.nextInt(); switch (d) { case 1: { s.isFull(); break; } case 2: { s.isEmpty(); break; } case 3: { s.display(); break; } } System.out.println("Enter 0 to go back to the main menu"); System.out.println("Enter any key to exit");

8th Jul 2022, 9:03 PM
Jai Anand
Jai Anand - avatar
1 Answer
+ 6
Code is cutoff. It would be better to save code and share link here.. There is no need for multiple scanners. and it won't work multiple scanners for the same stream.. So problem may be there... Also mention for the clarity, what is not working as per your expected behaviour...
8th Jul 2022, 9:33 PM
Jayakrishna 🇼🇳