style: enable LocalVariableName in CheckStyle (#5191)

* style: enable LocalVariableName in checkstyle

* Removed minor bug

* Resolved Method Name Bug

* Changed names according to suggestions
This commit is contained in:
S. Utkarsh
2024-05-28 23:59:28 +05:30
committed by GitHub
parent 81cb09b1f8
commit 25d711c5d8
45 changed files with 418 additions and 417 deletions

View File

@ -21,27 +21,27 @@ public final class InsertDeleteInArray {
// To insert a new element(we are creating a new array)
System.out.println("Enter the index at which the element should be inserted");
int insert_pos = s.nextInt();
int insertPos = s.nextInt();
System.out.println("Enter the element to be inserted");
int ins = s.nextInt();
int size2 = size + 1;
int[] b = new int[size2];
for (i = 0; i < size2; i++) {
if (i <= insert_pos) {
if (i <= insertPos) {
b[i] = a[i];
} else {
b[i] = a[i - 1];
}
}
b[insert_pos] = ins;
b[insertPos] = ins;
for (i = 0; i < size2; i++) {
System.out.println(b[i]);
}
// To delete an element given the index
System.out.println("Enter the index at which element is to be deleted");
int del_pos = s.nextInt();
for (i = del_pos; i < size2 - 1; i++) {
int delPos = s.nextInt();
for (i = delPos; i < size2 - 1; i++) {
b[i] = b[i + 1];
}
for (i = 0; i < size2 - 1; i++) {

View File

@ -28,20 +28,20 @@ class PageRank {
public double[] pagerank = new double[10];
public void calc(double totalNodes) {
double InitialPageRank;
double OutgoingLinks = 0;
double DampingFactor = 0.85;
double[] TempPageRank = new double[10];
int ExternalNodeNumber;
int InternalNodeNumber;
double initialPageRank;
double outgoingLinks = 0;
double dampingFactor = 0.85;
double[] tempPageRank = new double[10];
int externalNodeNumber;
int internalNodeNumber;
int k = 1; // For Traversing
int ITERATION_STEP = 1;
InitialPageRank = 1 / totalNodes;
System.out.printf(" Total Number of Nodes :" + totalNodes + "\t Initial PageRank of All Nodes :" + InitialPageRank + "\n");
int iterationStep = 1;
initialPageRank = 1 / totalNodes;
System.out.printf(" Total Number of Nodes :" + totalNodes + "\t Initial PageRank of All Nodes :" + initialPageRank + "\n");
// 0th ITERATION _ OR _ INITIALIZATION PHASE //
for (k = 1; k <= totalNodes; k++) {
this.pagerank[k] = InitialPageRank;
this.pagerank[k] = initialPageRank;
}
System.out.print("\n Initial PageRank Values , 0th Step \n");
@ -49,40 +49,40 @@ class PageRank {
System.out.printf(" Page Rank of " + k + " is :\t" + this.pagerank[k] + "\n");
}
while (ITERATION_STEP <= 2) { // Iterations
while (iterationStep <= 2) { // Iterations
// Store the PageRank for All Nodes in Temporary Array
for (k = 1; k <= totalNodes; k++) {
TempPageRank[k] = this.pagerank[k];
tempPageRank[k] = this.pagerank[k];
this.pagerank[k] = 0;
}
for (InternalNodeNumber = 1; InternalNodeNumber <= totalNodes; InternalNodeNumber++) {
for (ExternalNodeNumber = 1; ExternalNodeNumber <= totalNodes; ExternalNodeNumber++) {
if (this.path[ExternalNodeNumber][InternalNodeNumber] == 1) {
for (internalNodeNumber = 1; internalNodeNumber <= totalNodes; internalNodeNumber++) {
for (externalNodeNumber = 1; externalNodeNumber <= totalNodes; externalNodeNumber++) {
if (this.path[externalNodeNumber][internalNodeNumber] == 1) {
k = 1;
OutgoingLinks = 0; // Count the Number of Outgoing Links for each ExternalNodeNumber
outgoingLinks = 0; // Count the Number of Outgoing Links for each externalNodeNumber
while (k <= totalNodes) {
if (this.path[ExternalNodeNumber][k] == 1) {
OutgoingLinks = OutgoingLinks + 1; // Counter for Outgoing Links
if (this.path[externalNodeNumber][k] == 1) {
outgoingLinks = outgoingLinks + 1; // Counter for Outgoing Links
}
k = k + 1;
}
// Calculate PageRank
this.pagerank[InternalNodeNumber] += TempPageRank[ExternalNodeNumber] * (1 / OutgoingLinks);
this.pagerank[internalNodeNumber] += tempPageRank[externalNodeNumber] * (1 / outgoingLinks);
}
}
System.out.printf("\n After " + ITERATION_STEP + "th Step \n");
System.out.printf("\n After " + iterationStep + "th Step \n");
for (k = 1; k <= totalNodes; k++) {
System.out.printf(" Page Rank of " + k + " is :\t" + this.pagerank[k] + "\n");
}
ITERATION_STEP = ITERATION_STEP + 1;
iterationStep = iterationStep + 1;
}
// Add the Damping Factor to PageRank
for (k = 1; k <= totalNodes; k++) {
this.pagerank[k] = (1 - DampingFactor) + DampingFactor * this.pagerank[k];
this.pagerank[k] = (1 - dampingFactor) + dampingFactor * this.pagerank[k];
}
// Display PageRank

View File

@ -30,18 +30,18 @@ public final class ReturnSubsequence {
ans[0] = "";
return ans;
}
String[] SmallAns = returnSubsequence(givenString.substring(1)); // recursive call to get subsequences of substring starting from index
String[] smallAns = returnSubsequence(givenString.substring(1)); // recursive call to get subsequences of substring starting from index
// position=1
String[] ans = new String[2 * SmallAns.length]; // Our answer will be an array off string of size=2*SmallAns
String[] ans = new String[2 * smallAns.length]; // Our answer will be an array off string of size=2*smallAns
int i = 0;
for (; i < SmallAns.length; i++) {
ans[i] = SmallAns[i]; // Copying all the strings present in SmallAns to ans string array
for (; i < smallAns.length; i++) {
ans[i] = smallAns[i]; // Copying all the strings present in smallAns to ans string array
}
for (int k = 0; k < SmallAns.length; k++) {
ans[k + SmallAns.length] = givenString.charAt(0) + SmallAns[k]; // Insert character at index=0 of the given
for (int k = 0; k < smallAns.length; k++) {
ans[k + smallAns.length] = givenString.charAt(0) + smallAns[k]; // Insert character at index=0 of the given
// substring in front of every string
// in SmallAns
// in smallAns
}
return ans;
}

View File

@ -10,27 +10,27 @@ public final class RootPrecision {
// take input
Scanner scn = new Scanner(System.in);
// N is the input number
int N = scn.nextInt();
// n is the input number
int n = scn.nextInt();
// P is precision value for eg - P is 3 in 2.564 and 5 in 3.80870.
int P = scn.nextInt();
System.out.println(squareRoot(N, P));
// p is precision value for eg - p is 3 in 2.564 and 5 in 3.80870.
int p = scn.nextInt();
System.out.println(squareRoot(n, p));
scn.close();
}
public static double squareRoot(int N, int P) {
public static double squareRoot(int n, int p) {
// rv means return value
double rv;
double root = Math.pow(N, 0.5);
double root = Math.pow(n, 0.5);
// calculate precision to power of 10 and then multiply it with root value.
int precision = (int) Math.pow(10, P);
int precision = (int) Math.pow(10, p);
root = root * precision;
/*typecast it into integer then divide by precision and again typecast into double
so as to have decimal points upto P precision */
so as to have decimal points upto p precision */
rv = (int) root;
return rv / precision;

View File

@ -86,16 +86,16 @@ final class Sudoku {
return false;
}
public static void print(int[][] board, int N) {
public static void print(int[][] board, int n) {
// We got the answer, just print it
for (int r = 0; r < N; r++) {
for (int d = 0; d < N; d++) {
for (int r = 0; r < n; r++) {
for (int d = 0; d < n; d++) {
System.out.print(board[r][d]);
System.out.print(" ");
}
System.out.print("\n");
if ((r + 1) % (int) Math.sqrt(N) == 0) {
if ((r + 1) % (int) Math.sqrt(n) == 0) {
System.out.print("");
}
}
@ -114,11 +114,11 @@ final class Sudoku {
{0, 0, 0, 0, 0, 0, 0, 7, 4},
{0, 0, 5, 2, 0, 6, 3, 0, 0},
};
int N = board.length;
int n = board.length;
if (solveSudoku(board, N)) {
if (solveSudoku(board, n)) {
// print solution
print(board, N);
print(board, n);
} else {
System.out.println("No solution");
}