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

what is difference between scripts, smartforms and adobe forms

5 Answers  


How to find out the user exit for va01.

1 Answers  


Ordered List tag is

1 Answers  


Question:Why is mapping required? Computer 'Paging' & 'Segmentation'. Question:Give the disadvantages of Havander's Strategies. Question: What do you mean by Belady's Anomaly. - Describe with example. Question: Discuss the various function of OS. Question: Give a brief discussion on schedulers & Dispatchers with respect to process management.

0 Answers  


why main() method should not return any value

2 Answers   Accenture,






1.Mutating table

0 Answers  


WS-NUM PIC S9(05)V(02) SIGN TRAILING SEPARATE MOVE '0050000+' TO WS-NUM The value stored is 00500,00+ MOVE '0050000-' TO WS-NUM Then what is the value will be stored in WS-NUM? Am getting '-00500,00'.....>>> What should I declare to WS-NUM so that I can get correct values for both + & - signs.

0 Answers  


How do you initialize a static member of a class with return value of some function?

0 Answers   Yahoo,


what is the difference between SCAN AND CHECK,LOKUP AND XFOOT? where we can use thease opcodes? Can any body tell me real time senariao with example?

0 Answers  


merge sort time complexity

6 Answers   BFL, CDAC, IBM, Jawaharlal Nehru Technological University JNTU,


How can recruiter justified that the candidate is expert in Algorithm and datastructure for Software product development ?

0 Answers  


How to set fixed width in particular <td> in html? if i type more character in this <td> it will not push near <td>. this is my question. can u tell me the answer...

0 Answers   SoftSquare,


Categories