Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
export SONAR_ARGS="$SONAR_ARGS -Dsonar.host.url=https://sonarcloud.io"
export SONAR_ARGS="$SONAR_ARGS -Dsonar.coverage.jacoco.xmlReportPaths=$COVERAGE_FILE"


mvn -B clean verify sonar:sonar $SONAR_ARGS

# Submit Coverage Data to Codacy
Expand Down
56 changes: 54 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
# Compiled class file
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore

# Node artifact files
node_modules/
dist/

# Compiled Java class files
*.class

# Log file
# Log files
*.log

# Package files
*.jar

# Maven
target/
dist/

# JetBrains IDE
.idea/

# Unit test reports
TEST*.xml

# Generated by MacOS
.DS_Store

# Generated by Windows
Thumbs.db

# Applications
*.app
*.exe
*.war

# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv

# BlueJ files
*.ctxt

Expand All @@ -21,3 +62,14 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/target/

# Eclipse specific paths
**/.project
**/.settings
**/.classpath
**/target

# VS code
.vscode

24 changes: 24 additions & 0 deletions hackerrank/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.sampadadubey.java</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<relativePath>..</relativePath>
</parent>

<artifactId>hackerrank</artifactId>
<name>hackerrank</name>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>io.sampadadubey.java</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.sampadadubey.java.hackerrank.intro;

public class Java01WelcomeToJava {

public void print() {
System.out.println("Hello, World.");
System.out.println("Hello, Java.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.sampadadubey.java.hackerrank.intro;

import java.io.InputStream;
import java.util.Scanner;

public class Java02StdinStdout {

public void run(final InputStream input) {

final Scanner scanner = new Scanner(input);

final int number1 = scanner.nextInt();
final int number2 = scanner.nextInt();
final int number3 = scanner.nextInt();

scanner.close();

System.out.printf("%d%n%d%n%d%n", number1, number2, number3);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.sampadadubey.java.hackerrank.intro;

import static io.sampadadubey.java.common.NumberConstants.FIVE;
import static io.sampadadubey.java.common.NumberConstants.ONE;
import static io.sampadadubey.java.common.NumberConstants.SIX;
import static io.sampadadubey.java.common.NumberConstants.TWENTY;
import static io.sampadadubey.java.common.NumberConstants.TWO;

import java.io.InputStream;
import java.util.Scanner;

public class Java03IfElse {

static final String WEIRD = "Weird";

static final String NOT_WEIRD = "Not Weird";

public void run(final InputStream input) {

final Scanner scanner = new Scanner(input);

final int number = scanner.nextInt();

final String ans;

if (isOdd(number)) {
ans = WEIRD;
} else if (TWO <= number && number <= FIVE) {
ans = NOT_WEIRD;
} else if (SIX <= number && number <= TWENTY) {
ans = WEIRD;
} else {
ans = NOT_WEIRD;
}

System.out.println(ans);

scanner.close();
}

private boolean isOdd(final int number) {
// Bitwise AND(&) of Number and 1
return (number & ONE) == ONE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.sampadadubey.java.hackerrank.intro;

import java.io.InputStream;
import java.util.Scanner;

public class Java04StdinStdout2 {

public void run(final InputStream input) {

final Scanner scan = new Scanner(input);

final int intValue = scan.nextInt();
final double doubleValue = scan.nextDouble();
scan.nextLine();
final String stringValue = scan.nextLine();

System.out.println("String: " + stringValue);
System.out.println("Double: " + doubleValue);
System.out.println("Int: " + intValue);

scan.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.sampadadubey.java.hackerrank.intro;

import static io.sampadadubey.java.common.NumberConstants.THREE;

import java.io.InputStream;
import java.util.Scanner;

public class Java05OutputFormatting {

public void run(final InputStream input) {

final Scanner scanner = new Scanner(input);

System.out.println("================================");

for (int index = 0; index < THREE; index++) {
final String string = scanner.next();
final int integer = scanner.nextInt();
System.out.printf("%-15s%03d\n", string, integer);
}

System.out.println("================================");

scanner.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.sampadadubey.java.hackerrank.intro;

import static io.sampadadubey.java.common.NumberConstants.TEN;

public class Java06Loops1 {

public void run(final int number) {
for (int index = 1; index <= TEN; index++) {
System.out.printf("%d x %d = %d\n", number, index, number * index);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.sampadadubey.java.hackerrank.intro;

import static io.sampadadubey.java.common.NumberConstants.TWO;

import java.io.InputStream;
import java.util.Scanner;

public class Java07Loops2 {

public void run(final InputStream input) {

final Scanner scanner = new Scanner(input);

final int lines = scanner.nextInt();

for (int index = 0; index < lines; index++) {

final int number1 = scanner.nextInt();
final int number2 = scanner.nextInt();
final int iterations = scanner.nextInt();

System.out.println(getSequence(number1, number2, iterations));
}

scanner.close();
}

public String getSequence(final int number1, final int number2, final int iterations) {

final StringBuilder result = new StringBuilder();

int value = number1;

for (int index = 0; index < iterations; index++) {
value = value + ((int) Math.pow(TWO, index) * number2);
result.append(Integer.toString(value)).append(' ');
}

return result.toString().trim();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.sampadadubey.java.hackerrank.intro;

import java.io.InputStream;
import java.util.Scanner;

public class Java08DataTypes {

public void run(final InputStream input) {

final Scanner scanner = new Scanner(input);
final int totalInputs = scanner.nextInt();

scanner.nextLine();

for (int index = 0; index < totalInputs; index++) {

final String inputValue = scanner.nextLine();

checkType(inputValue);
}

scanner.close();
}

public void checkType(final String inputValue) {

try {

final long value = Long.parseLong(inputValue);

System.out.println(value + " can be fitted in:");

canFitInTypeByte(value);
canFitInTypeShort(value);
canFitInTypeInteger(value);

System.out.println("* long");

} catch (final NumberFormatException e) {
System.out.println(inputValue + " can't be fitted anywhere.");
}
}

private void canFitInTypeByte(final long value) {
if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
System.out.println("* byte");
}
}

private void canFitInTypeShort(final long value) {
if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
System.out.println("* short");
}
}

private void canFitInTypeInteger(final long value) {
if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
System.out.println("* int");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.sampadadubey.java.hackerrank.intro;

import java.io.InputStream;
import java.util.Scanner;

public class Java09EndOfFile {

public void run(final InputStream input) {

final Scanner scanner = new Scanner(input);

int lineNo = 1;

while (scanner.hasNext()) {

final String line = scanner.nextLine();

System.out.println(lineNo + " " + line);

lineNo++;
}

scanner.close();
}
}
Loading