How many ASCII Characters are there?
Now, write an algorithm for populating an array with every character (use Java as example language)
There are 256 ASCII characters.
//Java code to print every char in order:
int i = 0;
while(i <= 255) {
System.out.println((char)i + " = " + i);
i++;
}What is the formula for radial opposite? This is the opposite of a given integer on circle of m integers along its circumfrence. Eg: if circle is 10 in circumfrence, and provided i = 1 as input, then output 6.
import java.util.*;
class Dcoder
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String s1 = sc.next();
String s2 = sc.next();
int x = Integer.parseInt(s1);
int y = Integer.parseInt(s2);
int opposite = ((x/2)+y)%x;
System.out.println(opposite);
}
}Answer: ((x/2)+y)%x;
What is the distance formula for a coordinate grid? Convert this statement to code in Java.
Hint: Distance formula is the distance from any one point to another on a coordinate grid.
Math.sqrt((Y2-Y1)^2 + (X2-X1)^2)
Formula to find all prime numbers up to N:
Recommendation: Make an isPrime method to handle the inner loop.
class Dcoder {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int M = Integer.parseInt(sc.next());
int N = Integer.parseInt(sc.next());
while(M <= N) {
if(isPrime(M)) {
System.out.println(M);
}
M++;
}
}
static boolean isPrime(int M) {
if(M ==0 || M == 1) {
return false;
}
int k = 2;
while(k < M) {
if(M%k == 0) {
return false;
}
k++;
}
return true;
}
}FizzBuzz
a
Print all Primes
p
Fibbonacci
f
Remove Duplicates
r
Minimum USD Coin Change
c
Remove the Nth from the last node in a linked list.
r
Reverse a Linked List
r
Minimum Coin Change with ANY Coins
m
Convert Roman numerals to decimal
c
Shortest Distance to Char in a string
s
Shift an array left by d shifts
s
Determine whether two strings are permutations of each other
p
Maximum Sub Array (Kadane’s Algorithm)
s