-1

I cannot compile below and keep getting an error like this: enter image description here

I have done the code on visual studio code and the file name is like this enter image description here

public class Main {

    public static void main(String[] args) {
        Queue<Integer> q = new LinkedList<>();

        for (int i = 0; i < 5; i++) 
            q.add(i);
        
        System.out.println("Elements of queue " + q);

        int removedele = q.remove();
        System.out.println("removed element-" + removedele);
        System.out.println(q);

        int head = q.peek();
        System.out.println("head of queue-" + head);
        System.out.println(q);

        int size = q.size();
        System.out.println("Size of queue-" + size);
        System.out.println(q);
    }
}

I copied the code from my lecturers video and in her vid, the code compiles fine. But the source code is of extension .main. I cant seem to do that here

vaibhavsahu
  • 612
  • 2
  • 7
  • 19
erasvv
  • 11
  • 2

2 Answers2

0

add following at line at the top. import java.util.*;

-1

You are missing the import statements for Queue and LinkedList. Java needs to know what Classes you are referring to and where they can be found.

Add this to the top of the file:

import java.util.LinkedList;
import java.util.Queue;
Richard Stokes
  • 385
  • 3
  • 11