Skip to content

Instantly share code, notes, and snippets.

View nazmul202101's full-sized avatar
😍
Mind is Opening for Bigger Dreams.

Sheikh Nazmul Islam nazmul202101

😍
Mind is Opening for Bigger Dreams.
View GitHub Profile
@nazmul202101
nazmul202101 / posNeg.jar
Created December 10, 2016 15:48
Given 2 int values, return true if one is negative and one is positive. Except if the parameter "negative" is true, then return true only if both are negative.
//Given 2 int values, return true if one is negative and one is positive. Except if the parameter "negative" is true, then return true only if both are negative.
//posNeg(1, -1, false) → true
//posNeg(-1, 1, false) → true
//posNeg(-4, -5, true) → true
public boolean posNeg(int a, int b, boolean negative) {
if(a<0 && b>0 && negative==false){
return true;
}
@nazmul202101
nazmul202101 / backAround .jar
Created December 10, 2016 12:47
Given a string, take the last char and return a new string with the last char added at the front and back, so "cat" yields "tcatt". The original string will be length 1 or more
//Given a string, take the last char and return a new string with the last char added at the front and back, so "cat" yields "tcatt". The original string will be length 1 or more.
//backAround("cat") → "tcatt"
//backAround("Hello") → "oHelloo"
//backAround("a") → "aaa
public String backAround(String str) {
int length = str.length();
char length1 = str.charAt(length-1);
@nazmul202101
nazmul202101 / java.jar
Created December 9, 2016 19:15
Given two int values, return their sum. Unless the two values are the same, then return double their sum.
//Given two int values, return their sum. Unless the two values are the same, then return double their sum.
//sumDouble(1, 2) → 3
//sumDouble(3, 2) → 5
//sumDouble(2, 2) → 8
public int sumDouble(int a, int b) {
if(a==b){
return ((a+b)*2);
}
@nazmul202101
nazmul202101 / diff21.jar
Created December 9, 2016 02:13
Given an int n, return the absolute difference between n and 21, except return double the absolute difference if n is over 21.
//Given an int n, return the absolute difference between n and 21, except return double the absolute difference if n is over 21.
//diff21(19) → 2
//diff21(10) → 11
//diff21(21) → 0
public int diff21(int n) {
if(n<=21){
@nazmul202101
nazmul202101 / Given 2 positive int values, return the larger value that is in the range 10..20 inclusive, or return 0 if neither is in that range.
Created December 9, 2016 02:01
Given 2 positive int values, return the larger value that is in the range 10..20 inclusive, or return 0 if neither is in that range.
//Given 2 positive int values, return the larger value that is in the range 10..20 inclusive, or return 0 if neither is in that range.
//max1020(11, 19) → 19
//max1020(19, 11) → 19
//max1020(11, 9) → 11
public int max1020(int a, int b) {
if(a>=10 || a<=20){
return a;
}
//Given two temperatures, return true if one is less than 0 and the other is greater than 100.
//icyHot(120, -1) → true
//icyHot(-1, 120) → true
//icyHot(2, 120) → false
public boolean icyHot(int temp1, int temp2) {
if(temp1<0 && temp2>100 || temp2<0 && temp1>100 ){
return true;
}
//Warmup-1
//monkeyTrouble
//We have two monkeys, a and b, and the parameters aSmile and bSmile indicate if each is smiling. We are in trouble if they are both smiling or if neither of them is smiling. Return true if we are in trouble.
//monkeyTrouble(true, true) → true
//monkeyTrouble(false, false) → true
//monkeyTrouble(true, false) → false
public boolean monkeyTrouble(boolean aSmile, boolean bSmile) {
if(aSmile==bSmile){
public static void main(String[] args) {
try {
Scanner sc = new Scanner(new File(args[0]));
int n = Integer.parseInt(sc.next());
for (int i = 0; i < n; i++) {
System.out.println(sc.next()); // TEST
}
} catch (FileNotFoundException e) {
//Given two int values, return their sum. Unless the two values are the same, then return double their sum.
//sumDouble(1, 2) → 3
//sumDouble(3, 2) → 5
//sumDouble(2, 2) → 8
public int sumDouble(int a, int b) {
if(a==b){
return a+b;
//Warmup-1
//intMax
// intMax
// Given three int values, a b c, return the largest.
public int intMax(int a, int b, int c) {
int max=0;
if(a>b && a>c){
return a;
}