This section is dedicated to my viewers.Here they can ask question and I will be happy to help or redirect to some page what is best suitable for them.

Hi Animesh,I am bit confused with valgar fraction definition.What is vulgar fraction?? can you write a small program to determine a vulgar fraction??

Thanks

Arindam

Hi Arindam,Thank you very much for writting this.Let me tell you I got confused too by seeing the vulgar fraction definition!!!How ever i have taken help from http://www.wordreference.com/definition/vulgar%20fraction

##
__A vulger fraction:__

__A vulger fraction:__

A vulger fraction is a fraction in which denominator is an integer other than 10,100,1000.....

like -3/4,4/5,5/7 etc.

## Logic to write a vulger fraction determination

Well the logic is...1.take the fraction in x/y form from user

2.It will come as a string

3.Split the String with "/"

4. Find out the second number

5.Check if that is any multipler of 10.While we modulo operation with 10 ,it should not give any remainer

6.Determine the vulger fraction.

## Lets code

1.take the fraction in x/y form from user-----take the input the code is here

2.It will come as a string

3.Split the String with "/"

4. Find out the second number

5.Check if that is any multipler of 10.While we modulo operation with 10 ,it should not give any remainer

6.Determine the vulger fraction.

2.It will come as a string

3.Split the String with "/"

4. Find out the second number

5.Check if that is any multipler of 10.While we modulo operation with 10 ,it should not give any remainer

6.Determine the vulger fraction.

public class Vulger {

public Vulger() {

int deno;

// this is where you take user input

String fraction="3/1000";

String [] temp = null;

//Split it with "/"

temp= fraction.split("/");

//Change it integer from String

deno=Integer.parseInt( temp[1] );

//Here the main logic comes checking if it is divisible by 10 and making sure denominator is only a subset of multiplier of 10 like 10,100,1000.... not 20,30,40...etc

if (((deno%10)==0) && (checkval(deno)))

{

System.out.println(fraction+" is not a vulger fraction");

}

else

System.out.println(fraction+" is a vulger fraction");

}

public static void main(String[] Args) {

new Vulger();

}

private boolean checkval(int deno) {

//making sure denominator is only a subset of multiplier of 10 like 10,100,1000.... not 20,30,40...etc

int res=1;

do

{

res=deno%10;

deno=deno/10;

}

while (deno>=1);

if (res==1)

{

return true;

}

else

return false;

}

}

How to determine a vulgar fraction in java
Reviewed by Animesh Chatterjee
on
January 10, 2012
Rating:

## No comments: