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
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 |
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 |
how to convert infix expression to prefix expression?
You are given a dictionary of all valid words. You have the following 3 operations permitted on a word: delete a character, insert a character, replace a character. Now given two words - word1 and word2 - find the minimum number of steps required to convert word1 to word2. (one operation counts as 1 step.)
What is the difference between DECISION COVERAGE(DC) and MODIFIED CONDITION/DECISION COVERAGE(MCDC)?
Describe the following: (i) DNS (ii) Name Resolution (iii) Subnet Masking (iv) Urgent Pointer
which property is used to display the advertisements with adrotator control
What is meant by spooling
what is the difference between an application and service??? i mean service which runs as in services.msc.
can we convert .class file to dll file
can we allocate memory for interface? if no then why?
what is the difference between uservariables and systemvariables (in Environmental variables)???
What is test execution and when will we start execution please send me one example for this question
iam confused among testing ,.net and java. can anybody help me.