binary to decimal==>1001 to 9
package new_practice;
//8421
public class bi_dec_pro {
static int dec=0;
public static void main(String[] args) {
int no=1001;
int base=2;
int power=0;
int d=finddec(no,base,power);
System.out.println(d);
}
private static int finddec(int no, int base, int power) {
while(no>0)
{
int rev=no%10;
int result=rev*find_power(base,power);
dec=dec+result;
no=no/10;
power++;
}
return dec;
}
private static int find_power(int base, int power) {
int result=1;
while(power>0)
{
result=result*base;
power--;
}
return result;
}
}
output:9
**decimal to binary==>9 To 1001**
package new_practice;
public class dec_binary_num {
public static void main(String[] args) {
int no=9;
String binary="";
while(no>0)
{
binary=(no%2)+binary;
no=no/2;
}
System.out.println(binary);
}
}
output:1001
Fibonacci series without third variable
package new_practice;
public class fib_no_series {
public static void main(String[] args) {
int f = -1;
int s = 1;
while ((f + s) < 13) {
System.out.println(f + s + " ");
s = f + s;
f = s - f;
}
}
}
0 1 1 2 3 5 8