The following issues were found
lectures/7-methods/code/src/com/kunal/Sum.java
9 issues
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
Line: 24
// c++;
}
if (c * c > n) {
System.out.println("Prime");
}
}
}
Reported by PMD.
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.
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.
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
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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
Line: 38
int b = 40;
if (a != 35) {
System.out.println("Hello World");
}
}
}
Reported by PMD.
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.
Line: 15
}
*/
int salary = 25400;
// if (salary > 10000) {
// salary = salary + 2000;
// } else {
// salary = salary + 1000;
// }
Reported by PMD.
Line: 35
// System.out.println(salary);
int a = 10;
int b = 40;
if (a != 35) {
System.out.println("Hello World");
}
}
Reported by PMD.
Line: 37
int a = 10;
int b = 40;
if (a != 35) {
System.out.println("Hello World");
}
}
}
Reported by PMD.
Line: 15
}
*/
int salary = 25400;
// if (salary > 10000) {
// salary = salary + 2000;
// } else {
// salary = salary + 1000;
// }
Reported by PMD.
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
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.
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.
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.
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.
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.
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.
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
Line: 45
// }
switch (day) {
case 1, 2, 3, 4, 5 -> System.out.println("Weekday");
case 6, 7 -> System.out.println("Weekend");
}
}
}
Reported by PMD.
Line: 46
switch (day) {
case 1, 2, 3, 4, 5 -> System.out.println("Weekday");
case 6, 7 -> System.out.println("Weekend");
}
}
}
Reported by PMD.
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.
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.
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.
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
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.
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.
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.
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.
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.
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
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.
Line: 13
if (ch >= 'a' && ch <= 'z') {
System.out.println("Lowercase");
} else {
System.out.println("Uppercase");
}
}
}
Reported by PMD.
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.
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.
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.
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.