Programs in JAVA to get the remainder and quotient of given two numbers without using % and / operators?

Answers were Sorted based on User's Feedback



Programs in JAVA to get the remainder and quotient of given two numbers without using % and / operat..

Answer / swap1710

import java.util.*;
class WithoutO
{
public static void main(String args[])
{

int res,rem=0,num,div,qu=0;

Scanner s=new Scanner(System.in);
System.out.println("Enter number:");
num=s.nextInt();
System.out.println("Enter divisor:");
div=s.nextInt();

for(int i=1;i<num;i++)
{
res=div*i;

if(res>num)
{
res=res-div;
qu=i-1;
rem=num-res;
break;
}
}
System.out.println("Quotient:" +qu);
System.out.println("Remainder:" +rem);


}
}


/*
Output
D:Javap>java WithoutO
Enter number:
92
Enter divisor:
4


Quotient:23
Remainder:0

*/

Is This Answer Correct ?    0 Yes 0 No

Programs in JAVA to get the remainder and quotient of given two numbers without using % and / operat..

Answer / swap1710

import java.util.*;
class Rem
{
public static void main(String args[])
{
double f,qu,remi;
int i,qu1;
Scanner s= new Scanner(System.in);
System.out.println("Enter No..");
f=s.nextFloat();
qu=f*0.1;
qu1=(int)qu;
remi=(qu-qu1)*10;
System.out.println("quotient=" +qu1);
System.out.println("Reminder="+(int)remi);
System.out.println(qu1+"*10" + "+" +(int)remi+"="+(int)f);
}
}

/*
Output:


D:Javap>java Rem
Enter No..
45
quotient=4
Reminder=5
4*10+5=45
*/

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More Programming Languages AllOther Interview Questions

can we convert .class file to dll file

1 Answers  


how many languages .net is supporting now?

2 Answers  


how to convert the data from HTML file to SAS dataset?

0 Answers   Accenture,


How to call static method in Java?

2 Answers   Epoch,


How to use string functions in QTP?give some examples

1 Answers  






what is the main usage of an abstract keyword?please follow the program class A { void display() { System.out.println("hai"); } void print() { } } class B extends A { void print() { System.out.println("Hello"); } } In this program i was gives the implementation of print() according to my requirements in subclass.And there is no definition in superclass then why we can use abstract keyword before a method that i want to gives definition in other classes,is any mistakes in the above usage of method?

0 Answers  


when we use mantis? how learn mantis?

0 Answers  


explain how to make a control visible and invisible during runtime

3 Answers  


What parameters are used to run a JCL JOB on a perticular DAY and TIME and DATE

1 Answers  


For a binary tree with n nodes, How many nodes are there which has got both a parent and a child?

0 Answers  


what is the diff bw sql direct and jdbc update can't we do select and updating operation in sql direct

0 Answers   HP,


how can i split string in a textbox in windows appication using C#.net

0 Answers   IBM,


Categories