Hi all,i have Big problem mmm that the array must has the length but my program cann't be. Becase the array depend on the loop so i don't want to give a number like 20 or 100 .
I searched through my book and didn't found anything.
So in java i have to add number to my array,it work greet but i donn't want to do it.
Please Help.
I do it in php like this.
I searched through my book and didn't found anything.
So in java i have to add number to my array,it work greet but i donn't want to do it.
Please Help.
Code:
import javax.swing.JOptionPane;
public class ConvertDtoB{
public static void main(String arg[]){
int ircounter=-1;
int[] iarray=new int[20];
int[] rarray=new int[20];
float number;
int asas,f1,r2;
number=(int)Float.parseFloat(JOptionPane.showInputDialog("Enter number"));
System.out.println("The binary of the following decimal number "+number+" is:");
asas=(int)number;
int d2=2;
while(d2==2)
{
f1=asas/2;
r2=(int)asas-(f1*2);
ircounter++;
iarray[ircounter]=f1;
rarray[ircounter]=r2;
System.out.println(rarray[ircounter]);
if(f1!=0){asas=f1;}else{break;}
}
}
}
I do it in php like this.
Code:
<?php
class d2b{
var $iarray=array();
var $rarray=array();
function d2b($asas){
$f1=$asas/2;
$f1=intval($f1);
$r2=($asas)-($f1*2);
array_push($this->iarray,$f1);
//add value to the binary array
array_push($this->rarray,$r2);
//if the reminder != 0 loop it
if($f1!=0){d2b::d2b($f1);}
}
}
$D2b=new d2b(125);
print_r($D2b);
?>
Comment