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

how to remove header and footer in jcl using sort utility

0 Answers   CTS,


you have a computer with 80GB hard disk and ubuntu 8.04 is installed on entire hard disk.now you have to create a seprate partition for windows OS and install win XP as dual boot.write down the steps involved along with the commands

1 Answers   Anand Group, Indian Navy, TCS,


what is the difference between java , sap ,.net , orecle apps ?

1 Answers  


what are the differences between CONS, LIST, and APPEND

0 Answers   Comtech,


Full from of MP3?

2 Answers  






What is the difference b/w Object base and object oriented programming?

1 Answers  


< No Frames > tag is used for

0 Answers  


what is the pl/sql block size in oracle 10g and 11g?

0 Answers  


design a counter with the following repeated binary sequence: 0, 1, 2, 3, 4, 5, 6, 7, 8 using JK Flip Flop.

3 Answers   College School Exams Tests, IBD, IBM, Ignou, IIIT, Nortech, TCS, UOS,


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

0 Answers  


what is difference between IF-ELSE-ENDIF and IIF.

2 Answers  


what are importance in problem tracking

0 Answers  


Categories