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
Which CRM is better to opt, Sebiel CRM or Salesforce CRM or sap CRM? which institute is best one in hyderabad
how can we maintain the previous version scripts to new version.
THE CHANNEL IN DATA COMMUNICATION CAN BE?
why we need to take u?
Have you used callsymputx? what points need to be kept in mind when using it?
Write a shell program to test whether a given year is leap year or not ?
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.
what is d main diff between the java and .net framework
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?
can any one suggestion me present which course(except java,.net) has huge demand in the market?
kindly send interview materials
Find out the list of roles which gives access to GUI activities? thanks in advance
which book we learned this mantis? how many version are realsed this mantis upto now?
what is apt_dump_score in datastage where it is useful
what is web configuration file