Results 1 to 17 of 17
 04232008, 05:09 PM #1Member
 Join Date
 Apr 2008
 Posts
 31
 Rep Power
 0
Dividing numbers with remainders showing
I am looking to Dividing numbers within java. the code that i have at the minute is
Java Code:public synchronized void setProduct (int number) { this.product = (number / number); }
Java Code:if (selection==2) { // Returing the sum of the numbers int i = 1; int number = 0; int sendNum = 0; do { System.out.println("Enter Number: " + i); String num = br.readLine(); sendNum = Integer.parseInt(num); stub.setProduct(sendNum); i++; }while(i<=4); number = stub.getProduct(); System.out.println("NUMBER " + number); }//end if
 04232008, 10:25 PM #2Member
 Join Date
 Apr 2008
 Posts
 3
 Rep Power
 0
Please describe in words what you want to do.
From your code it's not clear what your program should do. Please describe your problem(s) in words.
 04232008, 11:59 PM #3Member
 Join Date
 Apr 2008
 Posts
 31
 Rep Power
 0
I want the program to be able to divide numbers like 100/2/2/2 and then have it out put 12.5. I want to input the numbers tho and they will not be the same every time.
 04242008, 04:58 AM #4
12.5? where is the remainder? 5 in .5 is a decimal number....
100/2 = 50
50/2 = 25
25/2 = 12.5
12 * 2 = 24
25  24 = 1
Your remainder is 1...
Java Code:int dividend = 100; int divisor = 2; int times = 3; int start = 0; while(start<(times1)){ dividend /= divisor; start++; } int final_quotient = 0; while(dividend>=divisor){ final_quotient++; dividend = divisor; } System.out.println("Quotient: "+final_quotient+" Remainder: "+dividend);
Last edited by sukatoa; 04242008 at 05:01 AM.
freedom exists in the world of ideas
 04242008, 08:39 AM #5
Use doubles or floats. the int data type is exactly that an Integer. Doubles have some decimal places and floats have even more.
 04242008, 09:44 AM #6
By the way, my codes above is just based on calculation's flow....
freedom exists in the world of ideas
 04242008, 09:55 AM #7Member
 Join Date
 Apr 2008
 Posts
 31
 Rep Power
 0
I know but as i said i can enter what ever numbers i like at the start. the numbers will not be predefined
 04242008, 10:23 AM #8
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 20
 04242008, 10:27 AM #9
 04242008, 10:31 AM #10
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 20
I think so that Sanjeev. Seems that Sukatoa try to do the same thing. :)
 04242008, 10:37 AM #11Member
 Join Date
 Apr 2008
 Posts
 31
 Rep Power
 0
No i can divide by anything i want to
 04242008, 11:01 AM #12
 04242008, 11:07 AM #13
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 20
So he need to handle user inputs there, isn't Sanjeev?
 04242008, 11:11 AM #14
 04242008, 11:27 AM #15Member
 Join Date
 Apr 2008
 Posts
 31
 Rep Power
 0
I got it working my self. All i did was this.average += number;
this.average2 = average /4;
this allowed me to input any numbers that i like and also return numbers
 04242008, 11:36 AM #16
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,370
 Blog Entries
 1
 Rep Power
 20
I'm not clear what exactly you want to do. Are you try to find the sum of few numbers and then find the average? If so, how did you change the number of values?
 04242008, 05:39 PM #17Member
 Join Date
 Apr 2008
 Posts
 2
 Rep Power
 0
The math package has divideAndRemainder() that does this. I made a short example, inputs are strings so you may have to jump through a few hoops.
<code>
import java.math.*;
public class divideWithRemainder
{
public static void main (String [] args){
// Create via a string, other options are available
BigDecimal num1 = new BigDecimal("1137");
BigDecimal num2 = new BigDecimal("83");
// an array to hold the result
BigDecimal[] num3 = new BigDecimal[2];
System.out.println ("divide " + num1 + " by " + num2 + " return both result and remainder");
num3 = num1.divideAndRemainder(num2);
System.out.println ("quotient = " + num3[0] + " remainder = " + num3[1]);
}
}
</code>
Similar Threads

Need Help showing text in JTextArea
By GuyFawkes in forum AWT / SwingReplies: 3Last Post: 05052008, 09:19 AM 
Quotients/Remainders (Loops *Need Help*)
By Zebra in forum New To JavaReplies: 2Last Post: 04172008, 03:08 PM 
[SOLVED] Integers (averages and remainders)...need help
By Zebra in forum New To JavaReplies: 4Last Post: 04162008, 01:26 PM 
Error Messages Not Showing Up
By nvidia in forum Web FrameworksReplies: 0Last Post: 04072008, 10:41 PM 
Why isn't this showing?
By JToolTip in forum Java AppletsReplies: 2Last Post: 07072007, 11:54 PM
Bookmarks