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
hi i m deepak my shedule for NIC pi is 17 Apr please contact me if anybody has interview on same day or give me some idea who have faced
WHAT IS MAIN IMPORTANT THING IN SOFTWARE?
How to set fixed width in particular
Given a set. Write the pseudo code to get all the subsets for the given set. Eg. Input : {1,2} Output : (),(1),(2),(1,2)
what is the work of 1tier,2tier,&ntier? Plz Explain it!
in cobol,wat is the difference in using 'set index in occurs clause' ....and 'occurs depending-on clause'
what are the differences between CONS, LIST, and APPEND
shall we execute our java programmes in jre
How can we develop a multi-tier application in Java?
what is the certificates in biztalk?
Where do we need Operator overloading?
Please describe an example where you used object orientation in one of your programs.
When you deliver your C++ headers and C++ library of a class (what all can you change in the class so that application using your class does not need to recompile the code)
Display names and numbers of employees who have 5 years or more experience and salary less than Rs.15000 using array of structures (name, number, experience and salary)
3 members in a pf.how we read 3 members without using ovrdbf.using rg pgms....