The following issues were found

lectures/7-methods/code/src/com/kunal/Sum.java
9 issues
System.out.println is used
Design

Line: 11

              //        System.out.println(ans);

        int ans = sum3(20, 30);
        System.out.println(ans);
    }

    // pass the value of numbers when you are calling the method in main()
    static int sum3(int a, int b) {
        int sum = a + b;

            

Reported by PMD.

System.out.print is used
Design

Line: 23

                  // return the value
    static int sum2() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter number 1: ");
        int num1 = in.nextInt();
        System.out.print("Enter number 2: ");
        int num2 = in.nextInt();
        int sum = num1 + num2;
        return sum;

            

Reported by PMD.

System.out.print is used
Design

Line: 25

                      Scanner in = new Scanner(System.in);
        System.out.print("Enter number 1: ");
        int num1 = in.nextInt();
        System.out.print("Enter number 2: ");
        int num2 = in.nextInt();
        int sum = num1 + num2;
        return sum;
//        System.out.println("This will never execute");
    }

            

Reported by PMD.

System.out.print is used
Design

Line: 34

              
    static void sum() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter number 1: ");
        int num1 = in.nextInt();
        System.out.print("Enter number 2: ");
        int num2 = in.nextInt();
        int sum = num1 + num2;
        System.out.println("The sum = " + sum);

            

Reported by PMD.

System.out.print is used
Design

Line: 36

                      Scanner in = new Scanner(System.in);
        System.out.print("Enter number 1: ");
        int num1 = in.nextInt();
        System.out.print("Enter number 2: ");
        int num2 = in.nextInt();
        int sum = num1 + num2;
        System.out.println("The sum = " + sum);
    }


            

Reported by PMD.

System.out.println is used
Design

Line: 39

                      System.out.print("Enter number 2: ");
        int num2 = in.nextInt();
        int sum = num1 + num2;
        System.out.println("The sum = " + sum);
    }

    /*
        return_type name (arguments) {
            // body

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 5

              
import java.util.Scanner;

public class Sum {
    public static void main(String[] args) {
//        int ans = sum2();
//        System.out.println(ans);

        int ans = sum3(20, 30);

            

Reported by PMD.

Ensure that resources like this Scanner object are closed after use
Error

Line: 22

              
    // return the value
    static int sum2() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter number 1: ");
        int num1 = in.nextInt();
        System.out.print("Enter number 2: ");
        int num2 = in.nextInt();
        int sum = num1 + num2;

            

Reported by PMD.

Ensure that resources like this Scanner object are closed after use
Error

Line: 33

                  }

    static void sum() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter number 1: ");
        int num1 = in.nextInt();
        System.out.print("Enter number 2: ");
        int num2 = in.nextInt();
        int sum = num1 + num2;

            

Reported by PMD.

lectures/10-binary search/code/src/com/kunal/RBS.java
8 issues
System.out.println is used
Design

Line: 6

              public class RBS {
    public static void main(String[] args) {
        int[] arr = {4,5,6,7,0,1,2};
        System.out.println(findPivot(arr));
    }

    static int search(int[] nums, int target) {
        int pivot = findPivot(nums);


            

Reported by PMD.

Avoid reassigning parameters such as 'end'
Design

Line: 30

                      return binarySearch(nums, target, pivot + 1, nums.length - 1);
    }

    static int binarySearch(int[] arr, int target, int start, int end) {
        while(start <= end) {
            // find the middle element
//            int mid = (start + end) / 2; // might be possible that (start + end) exceeds the range of int in java
            int mid = start + (end - start) / 2;


            

Reported by PMD.

Avoid reassigning parameters such as 'start'
Design

Line: 30

                      return binarySearch(nums, target, pivot + 1, nums.length - 1);
    }

    static int binarySearch(int[] arr, int target, int start, int end) {
        while(start <= end) {
            // find the middle element
//            int mid = (start + end) / 2; // might be possible that (start + end) exceeds the range of int in java
            int mid = start + (end - start) / 2;


            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 3

              package com.kunal;
// https://leetcode.com/problems/search-in-rotated-sorted-array/submissions/
public class RBS {
    public static void main(String[] args) {
        int[] arr = {4,5,6,7,0,1,2};
        System.out.println(findPivot(arr));
    }

    static int search(int[] nums, int target) {

            

Reported by PMD.

The method 'findPivotWithDuplicates(int)' has a cyclomatic complexity of 13.
Design

Line: 70

                      return -1;
    }

    static int findPivotWithDuplicates(int[] arr) {
        int start = 0;
        int end = arr.length - 1;
        while (start <= end) {
            int mid = start + (end - start) / 2;
            // 4 cases over here

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 49

                  }

    // this will not work in duplicate values
    static int findPivot(int[] arr) {
        int start = 0;
        int end = arr.length - 1;
        while (start <= end) {
            int mid = start + (end - start) / 2;
            // 4 cases over here

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 70

                      return -1;
    }

    static int findPivotWithDuplicates(int[] arr) {
        int start = 0;
        int end = arr.length - 1;
        while (start <= end) {
            int mid = start + (end - start) / 2;
            // 4 cases over here

            

Reported by PMD.

Found 'DU'-anomaly for variable 'start' (lines '91'-'107').
Error

Line: 91

                              if (arr[start] > arr[start + 1]) {
                    return start;
                }
                start++;

                // check whether end is pivot
                if (arr[end] < arr[end - 1]) {
                    return end - 1;
                }

            

Reported by PMD.

lectures/5-first-java-program/first-idea-program/src/com/kunal/Prime.java
7 issues
System.out.print is used
Design

Line: 8

              public class Prime {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Please enter a number: ");
        int n = in.nextInt();
        if(n <= 1) {
            System.out.println("Neither prime nor composite");
            return;
        }

            

Reported by PMD.

System.out.println is used
Design

Line: 11

                      System.out.print("Please enter a number: ");
        int n = in.nextInt();
        if(n <= 1) {
            System.out.println("Neither prime nor composite");
            return;
        }
        int c = 2;
        while (c * c <= n) {
            if (n % c == 0) {

            

Reported by PMD.

System.out.println is used
Design

Line: 17

                      int c = 2;
        while (c * c <= n) {
            if (n % c == 0) {
                System.out.println("Not Prime");
                return;
            }
            c = c + 1;
            // c++;
        }

            

Reported by PMD.

System.out.println is used
Design

Line: 24

                          // c++;
        }
        if (c * c > n) {
            System.out.println("Prime");
        }
        
    }
}

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 5

              
import java.util.Scanner;

public class Prime {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Please enter a number: ");
        int n = in.nextInt();
        if(n <= 1) {

            

Reported by PMD.

Ensure that resources like this Scanner object are closed after use
Error

Line: 7

              
public class Prime {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Please enter a number: ");
        int n = in.nextInt();
        if(n <= 1) {
            System.out.println("Neither prime nor composite");
            return;

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 10

                      Scanner in = new Scanner(System.in);
        System.out.print("Please enter a number: ");
        int n = in.nextInt();
        if(n <= 1) {
            System.out.println("Neither prime nor composite");
            return;
        }
        int c = 2;
        while (c * c <= n) {

            

Reported by PMD.

lectures/10-binary search/code/src/com/kunal/SplitArray.java
7 issues
This for loop can be replaced by a foreach loop
Design

Line: 12

                      int start = 0;
        int end = 0;

        for (int i = 0; i < nums.length; i++) {
            start = Math.max(start, nums[i]); // in the end of the loop this will contain the max item fro the array
            end += nums[i];
        }

        // binary search

            

Reported by PMD.

Found 'DU'-anomaly for variable 'sum' (lines '23'-'44').
Error

Line: 23

                          int mid = start + (end - start) / 2;

            // calculate how many pieces you can divide this in with this max sum
            int sum = 0;
            int pieces = 1;
            for(int num : nums) {
                if (sum + num > mid) {
                    // you cannot add this in this subarray, make new one
                    // say you add this num in new subarray, then sum = num

            

Reported by PMD.

Found 'DD'-anomaly for variable 'sum' (lines '23'-'23').
Error

Line: 23

                          int mid = start + (end - start) / 2;

            // calculate how many pieces you can divide this in with this max sum
            int sum = 0;
            int pieces = 1;
            for(int num : nums) {
                if (sum + num > mid) {
                    // you cannot add this in this subarray, make new one
                    // say you add this num in new subarray, then sum = num

            

Reported by PMD.

Found 'DD'-anomaly for variable 'pieces' (lines '24'-'30').
Error

Line: 24

              
            // calculate how many pieces you can divide this in with this max sum
            int sum = 0;
            int pieces = 1;
            for(int num : nums) {
                if (sum + num > mid) {
                    // you cannot add this in this subarray, make new one
                    // say you add this num in new subarray, then sum = num
                    sum = num;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'sum' (lines '29'-'44').
Error

Line: 29

                              if (sum + num > mid) {
                    // you cannot add this in this subarray, make new one
                    // say you add this num in new subarray, then sum = num
                    sum = num;
                    pieces++;
                } else {
                    sum += num;
                }
            }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'sum' (lines '29'-'23').
Error

Line: 29

                              if (sum + num > mid) {
                    // you cannot add this in this subarray, make new one
                    // say you add this num in new subarray, then sum = num
                    sum = num;
                    pieces++;
                } else {
                    sum += num;
                }
            }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'pieces' (lines '30'-'30').
Error

Line: 30

                                  // you cannot add this in this subarray, make new one
                    // say you add this num in new subarray, then sum = num
                    sum = num;
                    pieces++;
                } else {
                    sum += num;
                }
            }


            

Reported by PMD.

lectures/10-binary search/code/src/com/kunal/RotationCount.java
7 issues
System.out.println is used
Design

Line: 6

              public class RotationCount {
    public static void main(String[] args) {
        int[] arr = {4,5,6,7,0,1,2};
        System.out.println(countRotations(arr));
    }

    private static int countRotations(int[] arr) {
        int pivot = findPivot(arr);
        return pivot + 1;

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 3

              package com.kunal;

public class RotationCount {
    public static void main(String[] args) {
        int[] arr = {4,5,6,7,0,1,2};
        System.out.println(countRotations(arr));
    }

    private static int countRotations(int[] arr) {

            

Reported by PMD.

The method 'findPivotWithDuplicates(int)' has a cyclomatic complexity of 13.
Design

Line: 37

                  }

    // use this when arr contains duplicates
    static int findPivotWithDuplicates(int[] arr) {
        int start = 0;
        int end = arr.length - 1;
        while (start <= end) {
            int mid = start + (end - start) / 2;
            // 4 cases over here

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 9

                      System.out.println(countRotations(arr));
    }

    private static int countRotations(int[] arr) {
        int pivot = findPivot(arr);
        return pivot + 1;
    }

    // use this for non duplicates

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 15

                  }

    // use this for non duplicates
    static int findPivot(int[] arr) {
        int start = 0;
        int end = arr.length - 1;
        while (start <= end) {
            int mid = start + (end - start) / 2;
            // 4 cases over here

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 37

                  }

    // use this when arr contains duplicates
    static int findPivotWithDuplicates(int[] arr) {
        int start = 0;
        int end = arr.length - 1;
        while (start <= end) {
            int mid = start + (end - start) / 2;
            // 4 cases over here

            

Reported by PMD.

Found 'DU'-anomaly for variable 'start' (lines '58'-'74').
Error

Line: 58

                              if (arr[start] > arr[start + 1]) {
                    return start;
                }
                start++;

                // check whether end is pivot
                if (arr[end] < arr[end - 1]) {
                    return end - 1;
                }

            

Reported by PMD.

lectures/6-conditions-loops/code/src/com/kunal/Conditionals.java
7 issues
System.out.println is used
Design

Line: 38

                      int b = 40;

        if (a != 35) {
            System.out.println("Hello World");
        }
    }
}

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 3

              package com.kunal;

public class Conditionals {

    public static void main(String[] args) {
        /*
            Syntax of if statements:
            if (boolean expression T or F) {
                // body

            

Reported by PMD.

Avoid unused local variables such as 'salary'.
Design

Line: 15

                          }
        */

        int salary = 25400;
//        if (salary > 10000) {
//            salary = salary + 2000;
//        } else {
//            salary = salary + 1000;
//        }

            

Reported by PMD.

Avoid unused local variables such as 'b'.
Design

Line: 35

              //        System.out.println(salary);

        int a = 10;
        int b = 40;

        if (a != 35) {
            System.out.println("Hello World");
        }
    }

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 37

                      int a = 10;
        int b = 40;

        if (a != 35) {
            System.out.println("Hello World");
        }
    }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'salary' (lines '15'-'40').
Error

Line: 15

                          }
        */

        int salary = 25400;
//        if (salary > 10000) {
//            salary = salary + 2000;
//        } else {
//            salary = salary + 1000;
//        }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'b' (lines '35'-'40').
Error

Line: 35

              //        System.out.println(salary);

        int a = 10;
        int b = 40;

        if (a != 35) {
            System.out.println("Hello World");
        }
    }

            

Reported by PMD.

lectures/7-methods/code/src/com/kunal/Questions.java
7 issues
System.out.print is used
Design

Line: 14

              
        for (int i = 100; i < 1000; i++) {
            if (isArmstrong(i)) {
                System.out.print(i + " ");
            }
        }
    }

    // print all the 3 digits armstrong numbers

            

Reported by PMD.

Avoid reassigning parameters such as 'n'
Design

Line: 20

                  }

    // print all the 3 digits armstrong numbers
    static boolean isArmstrong(int n) {
        int original = n;
        int sum = 0;

        while (n > 0) {
            int rem = n % 10;

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 5

              
import java.util.Scanner;

public class Questions {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
//        int n = in.nextInt();
//        boolean ans = isPrime(n);
//        System.out.println(ans);

            

Reported by PMD.

Avoid unused local variables such as 'in'.
Design

Line: 7

              
public class Questions {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
//        int n = in.nextInt();
//        boolean ans = isPrime(n);
//        System.out.println(ans);

        for (int i = 100; i < 1000; i++) {

            

Reported by PMD.

Ensure that resources like this Scanner object are closed after use
Error

Line: 7

              
public class Questions {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
//        int n = in.nextInt();
//        boolean ans = isPrime(n);
//        System.out.println(ans);

        for (int i = 100; i < 1000; i++) {

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 34

                  }

    static boolean isPrime(int n) {
        if (n <= 1) {
            return false;
        }
        int c = 2;
        while (c * c <= n) {
            if (n % c == 0) {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'in' (lines '7'-'17').
Error

Line: 7

              
public class Questions {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
//        int n = in.nextInt();
//        boolean ans = isPrime(n);
//        System.out.println(ans);

        for (int i = 100; i < 1000; i++) {

            

Reported by PMD.

lectures/6-conditions-loops/switch/src/com/kunal/Main.java
6 issues
System.out.println is used
Design

Line: 45

              //        }

        switch (day) {
            case 1, 2, 3, 4, 5 -> System.out.println("Weekday");
            case 6, 7 -> System.out.println("Weekend");
        }

    }
}

            

Reported by PMD.

System.out.println is used
Design

Line: 46

              
        switch (day) {
            case 1, 2, 3, 4, 5 -> System.out.println("Weekday");
            case 6, 7 -> System.out.println("Weekend");
        }

    }
}

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 5

              
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
//        String fruit = in.next();
//

            

Reported by PMD.

Ensure that resources like this Scanner object are closed after use
Error

Line: 8

              public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
//        String fruit = in.next();
//
//        switch (fruit) {
//            case "Mango" -> System.out.println("King of fruits");
//            case "Apple" -> System.out.println("A sweet red fruit");

            

Reported by PMD.

A switch with less than three branches is inefficient, use a if statement instead.
Performance

Line: 44

              //                break;
//        }

        switch (day) {
            case 1, 2, 3, 4, 5 -> System.out.println("Weekday");
            case 6, 7 -> System.out.println("Weekend");
        }

    }

            

Reported by PMD.

Switch statements should have a default label
Design

Line: 44

              //                break;
//        }

        switch (day) {
            case 1, 2, 3, 4, 5 -> System.out.println("Weekday");
            case 6, 7 -> System.out.println("Weekend");
        }

    }

            

Reported by PMD.

lectures/10-binary search/code/src/com/kunal/SearchInMountain.java
6 issues
Avoid reassigning parameters such as 'start'
Design

Line: 42

                      return start; // or return end as both are =
    }

    static int orderAgnosticBS(int[] arr, int target, int start, int end) {
        // find whether the array is sorted in ascending or descending
        boolean isAsc = arr[start] < arr[end];

        while(start <= end) {
            // find the middle element

            

Reported by PMD.

Avoid reassigning parameters such as 'end'
Design

Line: 42

                      return start; // or return end as both are =
    }

    static int orderAgnosticBS(int[] arr, int target, int start, int end) {
        // find whether the array is sorted in ascending or descending
        boolean isAsc = arr[start] < arr[end];

        while(start <= end) {
            // find the middle element

            

Reported by PMD.

Avoid reassigning parameters such as 'end'
Design

Line: 42

                      return start; // or return end as both are =
    }

    static int orderAgnosticBS(int[] arr, int target, int start, int end) {
        // find whether the array is sorted in ascending or descending
        boolean isAsc = arr[start] < arr[end];

        while(start <= end) {
            // find the middle element

            

Reported by PMD.

Avoid reassigning parameters such as 'start'
Design

Line: 42

                      return start; // or return end as both are =
    }

    static int orderAgnosticBS(int[] arr, int target, int start, int end) {
        // find whether the array is sorted in ascending or descending
        boolean isAsc = arr[start] < arr[end];

        while(start <= end) {
            // find the middle element

            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 18

                      return orderAgnosticBS(arr, target, peak+1, arr.length - 1);
    }

    public int peakIndexInMountainArray(int[] arr) {
        int start = 0;
        int end = arr.length - 1;

        while (start < end) {
            int mid = start + (end - start) / 2;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'isAsc' (lines '44'-'70').
Error

Line: 44

              
    static int orderAgnosticBS(int[] arr, int target, int start, int end) {
        // find whether the array is sorted in ascending or descending
        boolean isAsc = arr[start] < arr[end];

        while(start <= end) {
            // find the middle element
//            int mid = (start + end) / 2; // might be possible that (start + end) exceeds the range of int in java
            int mid = start + (end - start) / 2;

            

Reported by PMD.

lectures/6-conditions-loops/code/src/com/kunal/CaseCheck.java
6 issues
System.out.println is used
Design

Line: 11

                      char ch = in.next().trim().charAt(0);

        if (ch >= 'a' && ch <= 'z') {
            System.out.println("Lowercase");
        } else {
            System.out.println("Uppercase");
        }

    }

            

Reported by PMD.

System.out.println is used
Design

Line: 13

                      if (ch >= 'a' && ch <= 'z') {
            System.out.println("Lowercase");
        } else {
            System.out.println("Uppercase");
        }

    }
}

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 5

              
import java.util.Scanner;

public class CaseCheck {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char ch = in.next().trim().charAt(0);

        if (ch >= 'a' && ch <= 'z') {

            

Reported by PMD.

Ensure that resources like this Scanner object are closed after use
Error

Line: 7

              
public class CaseCheck {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char ch = in.next().trim().charAt(0);

        if (ch >= 'a' && ch <= 'z') {
            System.out.println("Lowercase");
        } else {

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 8

              public class CaseCheck {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char ch = in.next().trim().charAt(0);

        if (ch >= 'a' && ch <= 'z') {
            System.out.println("Lowercase");
        } else {
            System.out.println("Uppercase");

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 8

              public class CaseCheck {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char ch = in.next().trim().charAt(0);

        if (ch >= 'a' && ch <= 'z') {
            System.out.println("Lowercase");
        } else {
            System.out.println("Uppercase");

            

Reported by PMD.