Skip to content

Instantly share code, notes, and snippets.

@Happsson
Created November 1, 2014 13:06
Show Gist options
  • Select an option

  • Save Happsson/19da97ebf0d5c5fd5acd to your computer and use it in GitHub Desktop.

Select an option

Save Happsson/19da97ebf0d5c5fd5acd to your computer and use it in GitHub Desktop.
public class Labb1 {
public static int length = 1;
public static int n;
public static void main(String args[]) {
count(2);
String _n = "101";
n = _n.length();
shifter(_n);
counter(999);
}
//upg 1a
public static void count(int index) {
System.out.print(index);
if (index > 0) {
count(index - 1);
}
}
//upg 1b
public static void shifter(String _n){
System.out.print(_n);
if(n>0){
System.out.print(" -> ");
StringBuilder sN = new StringBuilder();
sN.append(_n);
char temp = sN.charAt(_n.length()-n);
sN.deleteCharAt(_n.length()-n);
if(temp == '0') sN.insert(_n.length()-n, '1');
if(temp == '1') sN.insert(_n.length()-n, '0');
--n;
shifter(sN.toString());
}
}
//upb 1c
public static void counter(int n) {
if(Math.abs(n/10f) >= 10){
length++;
counter(n/10);
}else{
if(Math.abs(n)>=10) length++;
System.out.println(length);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment