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

Which CRM is better to opt, Sebiel CRM or Salesforce CRM or sap CRM? which institute is best one in hyderabad

2060


how can we maintain the previous version scripts to new version.

1642


THE CHANNEL IN DATA COMMUNICATION CAN BE?

1757


why we need to take u?

1864


Have you used callsymputx? what points need to be kept in mind when using it?

1734


Write a shell program to test whether a given year is leap year or not ?

2453


Given: coordinates of rectangle-> left bottom and right top points. the rectangles create a hole.Find the maximum area of the hole. eg. 4 rectangles create a hole in between. find its area.

2191


what is d main diff between the java and .net framework

1728


SAS question: I have 50 fils a1,a2,...,a50. the primary key is upc. then if i want to merge all 50 files, the code is as follows, data test; merge a1 ... a50; by upc; run; we know that writing all 50 files name is time consuming, is there any standard format of this code?

1706


can any one suggestion me present which course(except java,.net) has huge demand in the market?

1826


kindly send interview materials

1484


Find out the list of roles which gives access to GUI activities? thanks in advance

1920


which book we learned this mantis? how many version are realsed this mantis upto now?

1629


what is apt_dump_score in datastage where it is useful

1697


what is web configuration file

1751