This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while True: | |
print("This program splits the seconds you enter into Days:Hours:Minutes:Seconds") | |
n = int(input("enter seconds")) | |
days = n // (24*60*60) | |
days_rem = n %(24*60*60) | |
hours = days_rem // (60*60) | |
hours_rem = days_rem % (60*60) | |
minutes = hours_rem//60 | |
seconds = hours_rem%60 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input("enter triangle number")) | |
ini = 10 | |
for x in range(1,n+1): | |
if (x==1): | |
print (1) | |
else: | |
ini = ini * 10 | |
print (ini) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
while True: | |
if (random.randint(1,2) == 1): | |
print("Right") | |
#print(random_number) | |
input("hit enter for next") | |
if (random.randint(1,2) == 2): | |
print("Left") | |
#print(random_number) | |
input("hit enter for next") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int binaryToDecimal (int binaryNumber){ | |
int digitIndex; | |
int decimalNum = 0; | |
int powerIndex = 0; | |
while(( binaryNumber != 0) && ( binaryNumber >0)){ | |
digitIndex = binaryNumber % 10; | |
decimalNum = decimalNum + (int)(Math.pow(2,powerIndex) * digitIndex); | |
binaryNumber = binaryNumber / 10; | |
powerIndex++; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int decimalNum; | |
//Converts decimal number to binary, where regex is 2 | |
Integer.toString(decimalNum,2); | |
//Converts decimal number to hexadecimal, where regex is 16 | |
Integer.toString(decimalNum,16); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
String originalString = "azzbyyyx"; | |
StringBuilder str = new StringBuilder(originalString); | |
int loopCounter = 0; | |
int repetitionCounter = 0; | |
while (true) { | |
if (loopCounter < str.length() - 1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int convertBits(int initialNumber, int newNumber) { | |
return Integer.bitCount(initialNumber ^ newNumber); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String[] common = {"the","of","and","a","to","in","is","you","that","it","he","was","for","on","are","as","with","his","they","I","at","be","this","have","from","or","one","had","by","word","but","not","what","all","were","we","when","your","can","said","there","use","an","each","which","she","do","how","their","if","will","up","other","about","out","many","then","them","these","so","some","her","would","make","like","him","into","time","has","look","two","more","write","go","see","number","no","way","could","people","my","than","first","water","been","call","who","oil","its","now","find","long","down","day","did","get","come","made","may","part"}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Many a times we do need the list of numbers in languages. i did a lot of times but couldnt find it, so i got the unfiltered list | |
//applied some regex and got the final list as follow. | |
//List of numbers from 1-100 in English | |
private String[] numbersArray_En = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", | |
"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", | |
"twenty-one", "twenty-two", "twenty-three", "twenty-four", "twenty-five", "twenty-six", "twenty-seven", "twenty-eight", "twenty-nine", "thirty", | |
"thirty-one", "thirty-two", "thirty-three", "thirty-four", "thirty-five", "thirty-six", "thirty-seven", "thirty-eight", "thirty-nine", "forty", | |
"forty-one", "forty-two", "forty-three", "forty-four", "forty-five", "forty-six", "forty-seven", "forty-eight", "forty-nine", "fifty", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//bNum = Initializing big interger to value. | |
BigInteger bNum = BigInteger.ONE; | |
// n = The input number whose factorial is to be calculated. | |
for (long i = 1; i <= n; i++) { | |
bNum = bNum.multiply(bNum.valueOf(i)); | |
} | |
//Storing the value of factorial in a string. | |
String factorialValue = String.valueOf(bNum); |
OlderNewer