3 4 5 Rule Discretization
3 4 5 Rule Discretization
3 4 5 Rule Discretization
*;
public class finalh
{
public static void main(String args[])
{
finalh h=new finalh();
int minrange=0;
int maxrange=0;
int low=0;
int high=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter Range");
boolean a=true;
///////INPUT FOR TOP LEVEL ELEMENTS//////////
while(a)
{
System.out.println("Enter Min Range");
minrange=sc.nextInt();
System.out.println("Enter Max Range");
maxrange=sc.nextInt();
if(minrange<maxrange)
{
a=false;
}
}
a=true;
////////////INPUT FOR LOW AND HIGH VALUE////////////////
while(a)
{
System.out.println("Enter value For Low");
low=sc.nextInt();
System.out.println("Enter value For High");
high=sc.nextInt();
if(low>minrange && high<maxrange)
{
a=false;
}
}
/////////NO OF DIGITS//////////////
int ihigh=h.digit(high);
int jlow=h.digit(low);
int dig=0;
if(ihigh>jlow)
{
dig=ihigh;
}
else
{
dig=jlow;
}
boolean flag=false;
///////////CHECKING FOR A NO IS ROUNDED OR NOT////////////////////
boolean checkhigh=h.chec(high,ihigh);
boolean checklow=h.chec(low,jlow);
//////////////CALCULATING MSB /////////////////////////
int lhigh=h.msb(high);
int klow=h.msb(low);
////////////////ROUNDEING NOS//////////////////////
if(low>0)
{
klow=h.round("min","positive",low, klow, dig, checklow);
}
else
{
klow=h.round("min","negative",low, klow, dig, checklow);
}
if(high>0)
{
lhigh=h.round("max","positive",high, lhigh, dig, checkhigh);
}
else
{
lhigh=h.round("max","negative",high, lhigh, dig, checkhigh);
}
if(low>0 && jlow<ihigh)
{
if(low<100)
{
klow=0;
}
else
{
klow=1;
while(ihigh>0)
{
klow=klow*10;
ihigh--;
}
klow=klow/10;
}
}
else if(low<0 && jlow<ihigh)
{
klow=-1;
while(ihigh>0)
{
klow=klow*10;
ihigh--;
}
klow=klow/10;
}
ihigh=h.digit(high);
if(high>0 && ihigh<jlow)
{
lhigh=1;
jlow--;
while(jlow>0)
{
lhigh=lhigh*10;
jlow--;
}
}
else if(high<0 && ihigh<jlow)
{
if(high>-100)
{
lhigh=0;
}
else
{
lhigh=-1;
jlow--;
while(jlow>0)
{
lhigh=lhigh*10;
jlow--;
}
}
}
////////////////PRINTTING RANGES////////////////
List<Integer> arr=new ArrayList<Integer>();
System.out.println("////////LEVEL ONE////////");
arr=h.rule(klow, lhigh);
int newmin=h.topround(minrange);
int newmax=h.topround(maxrange);
h.rule(newmin,klow);
h.rule(lhigh,newmax);
int no=arr.size();
no--;
System.out.println(".............LEVEL TWO.............");
for(int i=0;i<no;i++)
{
int arrmin=arr.get(i);
int arrmax=arr.get(i+1);
h.rule(arrmin,arrmax);
}
}