Question

In: Computer Science

public List<Item> findItems(Lookup query) { ArrayList<Item> matches = new ArrayList<Item>(); for (int i = 0 ;...

public List<Item> findItems(Lookup query)
{
ArrayList<Item> matches = new ArrayList<Item>();
for (int i = 0 ; i < numItems ; i++ )
{
Item item = items[i];
if (query.matches(item)) {
matches.add(item);
}
}

return matches;
}

"To improve readability, each line of code should be indented under its parent (i.e. methods should be indented under the class, code in methods should be indented under the method, code in if statements should be indented under the if, etc.). This if rcurly is 16 spaces from the margin and it should be at 12 spaces"

I keep getting the error on Eclipse someone please help

Solutions

Expert Solution

As per the code provided above, the if RCurly should be 8 spaces from the margin.

If it is telling you to put 12 spaces, then you must be putting this code inside a class or something.

So, I am providing the screenshot of the code for both the cases.

Screenshot of code if the given code is inside some class:

You can clearly see that, the rcurly of if has only 12 spaces not 16.

NOTE: You you find any difficulty in understanding, feel free to ask.


Related Solutions

public void printQueue(DoublyLinkedQueue<Integer> Q){ int len = Q.size(); int k = 0; for (int i=0; i...
public void printQueue(DoublyLinkedQueue<Integer> Q){ int len = Q.size(); int k = 0; for (int i=0; i < len; ++i){ k = Q.dequeue(); Q.enqueue(k);    System.out.println(Q.dequeue()); } } What is the complexity of this code? Select one: a. O(N), N = k b. Q(1) c. Q(N2), N = Q.size() d. O(M), M = Q.size() e. None of the alternatives is correct. which one?
public static void main(String [] args)     {         int[] a = new int[20];         a[0]...
public static void main(String [] args)     {         int[] a = new int[20];         a[0] = 0;         a[1] = 1;         for(int i = 2; i < 20; i++){             a[i] = a[i - 1] + a[i - 2];         }         for(int i = 0; i < a.length; i++)             System.out.println(a[i]);     } what would be the code when you convert this code, which is java into assembly code? Convert java into assembly code for the code...
import java.util.*; class Main { static ArrayList<String> list; public static List<String> createList(ArrayList<String> arrayList) { list =...
import java.util.*; class Main { static ArrayList<String> list; public static List<String> createList(ArrayList<String> arrayList) { list = arrayList; return list; } public static void printList(ArrayList<String> arrayList) { System.out.println("Printing in 4 ways\n"); // 1 System.out.println(arrayList); //2 for(String s:arrayList) System.out.print(s+" "); System.out.println(); //3 System.out.println(Arrays.deepToString(list.toArray())); //4 for(int i=0;i<arrayList.size();i++) System.out.print(arrayList.get(i)+" "); System.out.println(); } public static void filterList(ArrayList<String> arrayList) { System.out.println("Filtered in 2 ways\n"); ArrayList<String> copyArrayList = arrayList; //1 for(int i=0;i<arrayList.size();i++) { if(arrayList.get(i).contains("chuck")) { arrayList.remove(i); i--; } } System.out.println(arrayList); //2 copyArrayList.removeIf(str -> str.contains("chunk")); System.out.println(copyArrayList); }   ...
public class SinglyLikedList {    private class Node{        public int item;        public...
public class SinglyLikedList {    private class Node{        public int item;        public Node next;        public Node(int item, Node next) {            this.item = item;            this.next = next;        }    }       private Node first;    public void addFirst(int a) {        first = new Node(a, first);    } } 1. Write the method add(int item, int position), which takes an item and a position, and...
int f2 (int n) j = 0; while (j <n) {for (int i = 0; i...
int f2 (int n) j = 0; while (j <n) {for (int i = 0; i <n; ++ i) {cout << "j =" + j; j = j + 5; }}
In Java: int[] A = new int[2]; A[0] = 0; A[1] = 2; f(A[0],A[A[0]]); void f(int...
In Java: int[] A = new int[2]; A[0] = 0; A[1] = 2; f(A[0],A[A[0]]); void f(int x, int y) { x = 1; y = 3; } For each of the following parameter-passing methods, saw what the final values in the array A would be, after the call to f. (There may be more than one correct answer.) a. By value. b. By reference. c. By value-result.
I need to create a linked list that contains a fixed arraylist. Each new entry is...
I need to create a linked list that contains a fixed arraylist. Each new entry is added to array list. If the arraylist is full, create a new arraylist and add to the linklist. In java please.
import java.util.*; class A { int i, j, k; public A(int i, int j, int k)...
import java.util.*; class A { int i, j, k; public A(int i, int j, int k) { this.i=i; this.j=j; this.k=k; } public String toString() { return "A("+i+","+j+","+k+")"; } } class Main { public static void main(String[] args) { ArrayList<A> aL=new ArrayList<A>(); Random rand= new Random(1000); //1000 is a seed value for (int p=0; p<10; p++) { int i = rand.nextInt(100); int j = rand.nextInt(200); int k = rand.nextInt(300); aL.add(new A(i, j, k)); } System.out.println("----- Original arraylist------"); for (A a: aL)...
def compare_elevations_within_row(elevation_map: List[List[int]], map_row: int, level: int) -> List[int]: """Return a new list containing the three...
def compare_elevations_within_row(elevation_map: List[List[int]], map_row: int, level: int) -> List[int]: """Return a new list containing the three counts: the number of elevations from row number map_row of elevation map elevation_map that are less than, equal to, and greater than elevation level. Precondition: elevation_map is a valid elevation map. 0 <= map_row < len(elevation_map). >>> compare_elevations_within_row(THREE_BY_THREE, 1, 5) [1, 1, 1] >>> compare_elevations_within_row(FOUR_BY_FOUR, 1, 2) [0, 1, 3] """ for i in elevation_map[map_row]: differences=[0,0,0] if i<level: differences[0] += 1 elif i==level: differences[1]...
#include <iostream> using namespace std; int main() { int even=0,odd=0,sum=0,sum2=0,largest,smallest; int num,i; for ( i=1; i<=10;...
#include <iostream> using namespace std; int main() { int even=0,odd=0,sum=0,sum2=0,largest,smallest; int num,i; for ( i=1; i<=10; i++){ cout << " Enter " << i << " number: "; cin >> num; if ( num%2==0){ even++; sum+=num; } else { odd++; sum2+=num; if(num>largest){ largest = num; } if(num<largest) { smallest = num; } } cout << " The sum of even number is : " << sum << endl; cout << " The total-count of even number is : " <<...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT