The following issues were found
lectures/7-methods/code/src/com/kunal/Shadowing.java
4 issues
Line: 6
public class Shadowing {
static int x = 90; // this will be shadowed at line 8
public static void main(String[] args) {
System.out.println(x); // 90
int x; // the class variable at line 4 is shadowed by this
// System.out.println(x); // scope will begin when value is initialised
x = 40;
System.out.println(x); // 40
fun();
Reported by PMD.
Line: 10
int x; // the class variable at line 4 is shadowed by this
// System.out.println(x); // scope will begin when value is initialised
x = 40;
System.out.println(x); // 40
fun();
}
static void fun() {
System.out.println(x);
Reported by PMD.
Line: 15
}
static void fun() {
System.out.println(x);
}
}
Reported by PMD.
Line: 3
package com.kunal;
public class Shadowing {
static int x = 90; // this will be shadowed at line 8
public static void main(String[] args) {
System.out.println(x); // 90
int x; // the class variable at line 4 is shadowed by this
// System.out.println(x); // scope will begin when value is initialised
x = 40;
Reported by PMD.
lectures/7-methods/code/src/com/kunal/StringExample.java
4 issues
Line: 12
// System.out.println(message);
Scanner in = new Scanner(System.in);
System.out.print("Enter your name: ");
String naam = in.next();
String personalised = myGreet(naam);
System.out.println(personalised);
}
Reported by PMD.
Line: 15
System.out.print("Enter your name: ");
String naam = in.next();
String personalised = myGreet(naam);
System.out.println(personalised);
}
static String myGreet(String name) {
String message = "Hello " + name;
return message;
Reported by PMD.
Line: 5
import java.util.Scanner;
public class StringExample {
public static void main(String[] args) {
// String message = greet();
// System.out.println(message);
Reported by PMD.
Line: 11
// String message = greet();
// System.out.println(message);
Scanner in = new Scanner(System.in);
System.out.print("Enter your name: ");
String naam = in.next();
String personalised = myGreet(naam);
System.out.println(personalised);
}
Reported by PMD.
lectures/5-first-java-program/first-idea-program/src/com/kunal/Temperature.java
4 issues
Line: 8
public class Temperature {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Please enter temp in C: ");
float tempC = in.nextFloat();
float tempF = (tempC * 9/5) + 32;
System.out.println(tempF);
}
}
Reported by PMD.
Line: 11
System.out.print("Please enter temp in C: ");
float tempC = in.nextFloat();
float tempF = (tempC * 9/5) + 32;
System.out.println(tempF);
}
}
Reported by PMD.
Line: 5
import java.util.Scanner;
public class Temperature {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Please enter temp in C: ");
float tempC = in.nextFloat();
float tempF = (tempC * 9/5) + 32;
Reported by PMD.
Line: 7
public class Temperature {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Please enter temp in C: ");
float tempC = in.nextFloat();
float tempF = (tempC * 9/5) + 32;
System.out.println(tempF);
}
Reported by PMD.
lectures/10-binary search/code/src/com/kunal/InfiniteArray.java
4 issues
Line: 8
int[] arr = {3, 5, 7, 9, 10, 90,
100, 130, 140, 160, 170};
int target = 10;
System.out.println(ans(arr, target));
}
static int ans(int[] arr, int target) {
// first find the range
// first start with a box of size 2
int start = 0;
Reported by PMD.
Line: 27
return binarySearch(arr, target, start, end);
}
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: 27
return binarySearch(arr, target, start, end);
}
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://www.geeksforgeeks.org/find-position-element-sorted-array-infinite-numbers/
public class InfiniteArray {
public static void main(String[] args) {
int[] arr = {3, 5, 7, 9, 10, 90,
100, 130, 140, 160, 170};
int target = 10;
System.out.println(ans(arr, target));
}
Reported by PMD.
lectures/7-methods/code/src/com/kunal/VarArgs.java
4 issues
Line: 13
}
static void demo(int ...v) {
System.out.println(Arrays.toString(v));
}
static void demo(String ...v) {
System.out.println(Arrays.toString(v));
}
Reported by PMD.
Line: 17
}
static void demo(String ...v) {
System.out.println(Arrays.toString(v));
}
static void multiple(int a, int b, String ...v) {
}
Reported by PMD.
Line: 25
}
static void fun(int ...v) {
System.out.println(Arrays.toString(v));
}
}
Reported by PMD.
Line: 5
import java.util.Arrays;
public class VarArgs {
public static void main(String[] args) {
// fun();
// multiple(2, 3, "Kunal", "Rahul", "dvytsbhusc");
// demo();
}
Reported by PMD.
lectures/5-first-java-program/first-idea-program/src/com/kunal/Inputs.java
4 issues
Line: 5
import java.util.Scanner;
public class Inputs {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// System.out.print("Please enter some input: ");
// int rollno = input.nextInt();
// System.out.println("Your roll number is " + rollno);
Reported by PMD.
Line: 7
public class Inputs {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// System.out.print("Please enter some input: ");
// int rollno = input.nextInt();
// System.out.println("Your roll number is " + rollno);
// String name = input.next();
Reported by PMD.
Line: 7
public class Inputs {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// System.out.print("Please enter some input: ");
// int rollno = input.nextInt();
// System.out.println("Your roll number is " + rollno);
// String name = input.next();
Reported by PMD.
Line: 7
public class Inputs {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// System.out.print("Please enter some input: ");
// int rollno = input.nextInt();
// System.out.println("Your roll number is " + rollno);
// String name = input.next();
Reported by PMD.
lectures/8-arrays/code/src/com/kunal/ColNoFixed.java
4 issues
Line: 13
for (int row = 0; row < arr.length; row++) {
for (int col = 0; col < arr[row].length; col++) {
System.out.print(arr[row][col] + " ");
}
System.out.println();
}
}
}
Reported by PMD.
Line: 15
for (int col = 0; col < arr[row].length; col++) {
System.out.print(arr[row][col] + " ");
}
System.out.println();
}
}
}
Reported by PMD.
Line: 3
package com.kunal;
public class ColNoFixed {
public static void main(String[] args) {
int[][] arr = {
{1, 2, 3, 4},
{5, 6},
{7, 8, 9}
};
Reported by PMD.
Line: 11
{7, 8, 9}
};
for (int row = 0; row < arr.length; row++) {
for (int col = 0; col < arr[row].length; col++) {
System.out.print(arr[row][col] + " ");
}
System.out.println();
}
Reported by PMD.
lectures/5-first-java-program/first-idea-program/src/com/kunal/Sum.java
3 issues
Line: 13
float sum = num1 + num2;
System.out.println("Sum = " + sum);
}
}
Reported by PMD.
Line: 5
import java.util.Scanner;
public class Sum {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
float num1 = input.nextFloat();
float num2 = input.nextFloat();
Reported by PMD.
Line: 7
public class Sum {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
float num1 = input.nextFloat();
float num2 = input.nextFloat();
float sum = num1 + num2;
Reported by PMD.
lectures/8-arrays/code/src/com/kunal/Max.java
3 issues
Line: 6
public class Max {
public static void main(String[] args) {
int[] arr = {1, 3, 2, 9, 18};
System.out.println(maxRange(arr, 1, 3));
}
// work on edge cases here, like array being null
static int maxRange(int[] arr, int start, int end) {
Reported by PMD.
Line: 3
package com.kunal;
public class Max {
public static void main(String[] args) {
int[] arr = {1, 3, 2, 9, 18};
System.out.println(maxRange(arr, 1, 3));
}
// work on edge cases here, like array being null
Reported by PMD.
Line: 29
return maxVal;
}
static int max(int[] arr) {
if (arr.length == 0) {
return -1;
}
int maxVal = arr[0];
for (int i = 1; i < arr.length; i++) {
Reported by PMD.
lectures/8-arrays/code/src/com/kunal/Swap.java
3 issues
Line: 10
int[] arr = {1, 3, 23, 9, 18, 56};
// swap(arr, 0, 4);
reverse(arr);
System.out.println(Arrays.toString(arr));
}
static void reverse(int[] arr) {
int start = 0;
int end = arr.length-1;
Reported by PMD.
Line: 5
import java.util.Arrays;
public class Swap {
public static void main(String[] args) {
int[] arr = {1, 3, 23, 9, 18, 56};
// swap(arr, 0, 4);
reverse(arr);
System.out.println(Arrays.toString(arr));
Reported by PMD.
Line: 13
System.out.println(Arrays.toString(arr));
}
static void reverse(int[] arr) {
int start = 0;
int end = arr.length-1;
while (start < end) {
// swap
Reported by PMD.