A Tribute to SHOTTO

Advertisements

Power raise using Recursion

//Author : S.Mahbub - Uz - Zaman 
//Math.pow using Recursion


import java.util.*;
public class MathPow {  
    //We konw 5^5=5*5^4 -> 5^4=5*5^3 -> 5^3=5*5^2 -> 5^2=5*5^1 -> 5^1=5*5^0 -> 5^0=1 
    //something to the power 0 means 1, So this our base case
    public static double Pow (double base,double pow) {
        if(pow == 0) // Base Case #Recursive function breaking condition#
            return 1;
        else
            return base * Pow(base, pow - 1);
    }
    
    public static void main (String args []) {
        Scanner sc = new Scanner (System.in);
        double base = sc.nextDouble();
        double pow = sc.nextDouble();
        System.out.println((int)Pow(base, pow));
    }
}

Count the unique character in a String

public static int frq [] = new int [500];    
public static int countUniqueChar (String line) {
      Arrays.fill(frq, 0);
      int ans = 0;
      for(int i = 0; i < line.length(); ++i) {
          if(frq[line.charAt(i)] == 0) {
              frq[line.charAt(i)]++;
              ++ans;
          }
      }
      return ans;
}  

input
“aaaaaa”
“aaa aaa”
“abcdeabcde”
“YESyes”

output
1
2
5
6

Learning Terminal (OS X) Part 2: Starting

How to open Terminal, well there are several ways to do that

1. Open spotlight (cmd + space) and write terminal (like Windows + r then cmd)
2. Open Launchpad and then under Utilities you have terminal
3. Keep the terminal in the Dock
4. Make keyboard shortcut
http://www.shadowlab.org/Software/spark.php
http://www.red-sweater.com/fastscripts/

Now if you want any help regarding any commands

Type
man yourCommand
man ls

If you want to change the Terminal look, go to Preferences (cmd + ,) and change it your own way. You can set a background image also 😛

To exit the terminal with exit command
1. Terminal -> Preferences -> Settings
2. Go to Shell
3. Under “When the shell exits”
4. Select close if the shell exited cleanly