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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what are other resources are needed for this mantis?

1520


How to connect the .accdb database file of microsoft access to the Visual Basic 6.0 forms?

3703


What is test execution and when will we start execution please send me one example for this question

1429


in a VB application, where the data will be stored after manipulation? what is the syntax for that?

1825


what is difference between input parameter and output parameter.

4213






Given a Binary Search Tree, write a program to print the kth smallest element without using any static/global variable. You can?t pass the value k to any function also.

556


Please forward important interview and basic questions in VB6 on my email id: usneha_16@yahoo.co.in

1577


suppose we have ten members of a physical file but we want the output of last 5 members only.how to achieve that?

1494


what is throws keyword

2990


What is the difference between DECISION COVERAGE(DC) and MODIFIED CONDITION/DECISION COVERAGE(MCDC)?

1784


Iam using Microsoft Visual Studio to create a system for mobile store I want to know how to calculate mobile price that the customer buy and how to reduce quantity from the data base that we have for mobile .And also how to calculate revnue for each mobile and revnue for the total mobile

1482


How do i find out the number of parameters passed into function?

2215


V2 SOLUTIONS APTI paper is very easy there are 3 sections 1'st is quant problem on age train traveling speed is given length of train is given we have to find out length of bridge then prob on calender one date is given on Friday hv to find out day of othe date ans is Friday then there was 1 prob on percentage which was very easy ans was 21340 then 2’nd section was english grammer had has been being like that hv to fill in the blanks was very wasy then last section was find relative words there was five Q 1 pant ANS:-breath 2inquire ans :- ask And 3 more out of that 1 ‘s ans was:- body 4 And others ans was :-through THEN THEY HAVE GD There was three topics 1 should we allow india’s talent to go to abrod 2 protest against seperate state is justify 3 inturuption of politics in cricket Thats all guys i cleared both the rounds now preparing 4 interview best of luck

1777


4. What is the need of START 0? Instead if can we use any other numeric? If we use what will happen?

1897


along with oracle which language will be beneficial to have knowledge with,java,.net,since i m doing oracle have appeared for 8th sem BEIT,plz suggest

1388