473,804 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

more info on my question, ADDING LARGE INTEGERS, in java arrays

12 New Member
I need help in writing the addition , subtraction etc. method.

eample the add method must add large intergers,
say 2500 + 69587562. each number is entered in the subscript individually.


this is what i have done so far.I created the class,construct ors


public class Example
{
private int[] values;
private int min;
private int max;


Scanner Key= new Scanner(System. in);

public Example()
{
values=20;
min=0;
max=20;
}

public int ReadSize( int size)
{

System.out.prin tln("Enter the size of the array.")
size=key.nextIn t();

for(int min=0; min<size.length ;min ++)
{
values[min]=key.nextInt();
}
}
Oct 19 '06
18 5838
johnathan
12 New Member
could u wirte a method for me to see what it would look like, doing it the "FAIR method. thanks
Oct 24 '06 #11
r035198x
13,262 MVP
could u wirte a method for me to see what it would look like, doing it the "FAIR method. thanks
should look something like this. I have to go for now but you should make the neccessary changes to your code to make this compile and then try to fine tune it to get the correct results. I 'll be in tommorrow morning about 8 hrs from now but others may be able to help you before then
Expand|Select|Wrap|Line Numbers
  1. public LargeInteger add(LargeInteger num) {
  2.         int size = num.getMax() > getMax() ? num.getMax(): getMax();
  3.         LargeInteger result = new LargeInteger(size + 1);
  4.  
  5.         for(int i = 0; i < size; i++) {
  6.             int resultPos = size;
  7.             int carry = 0;
  8.             int numPos = num.getMax();
  9.             int thisPos = number.getMax();
  10.             int unit = 0;
  11.             int sum = carry + num.getDigit(numPos) + number.getDigit(thisPos);
  12.             if(sum > 10) {
  13.                 unit = sum - 10;
  14.                 carry = 1;
  15.             }
  16.             else {
  17.                 carry = 0;
  18.                 unit = sum;
  19.             }
  20.             result.setDigit(unit, resultPos);
  21.             resultPos = resultPos - 1;
  22.             numPos = numPos - 1;
  23.             thisPos = thisPos - 1;
  24.         }
  25.         return result;
  26.  
  27.  
  28.  
  29.     }
Oct 24 '06 #12
johnathan
12 New Member
this is what the program look like.

public class Quest
{
public static void main(String []args)
{

example test= new example (5);
example test2= new example(6);

example test3= new example(7);

test.readinfo() ;
test.printnum() ;

test2.readinfo( );
test2.printnum( );

test3.add(test, test2);



this is the class that i have so far. would u kindly help with the addition
subtraction methods. sorry am going to copy and paste this here.




public class example
{
private int [] values;


public example ()
{
values= new int[40];

}

public example(int size)
{
values=new int [size];
}

public void readinfo()
{
int ctr=0;
String asknum=JOptionP ane.showInputDi alog("Enter the numbers.");

for( int i=asknum.length () -1; i >=0; i--)
{
values [ctr]=asknum.charAt( i)-48;
ctr ++;
}
}

public void printnum()
{
for(int i=0; i<values.length ; i ++)
{
JOptionPane.sho wMessageDialog( null,"Display the numbers." + values[i]);

}
}

public void add( )
{
Oct 26 '06 #13
r035198x
13,262 MVP
this is what the program look like.

public class Quest
{
public static void main(String []args)
{

example test= new example (5);
example test2= new example(6);

example test3= new example(7);

test.readinfo() ;
test.printnum() ;

test2.readinfo( );
test2.printnum( );

test3.add(test, test2);



this is the class that i have so far. would u kindly help with the addition
subtraction methods. sorry am going to copy and paste this here.




public class example
{
private int [] values;


public example ()
{
values= new int[40];

}

public example(int size)
{
values=new int [size];
}

public void readinfo()
{
int ctr=0;
String asknum=JOptionP ane.showInputDi alog("Enter the numbers.");

for( int i=asknum.length () -1; i >=0; i--)
{
values [ctr]=asknum.charAt( i)-48;
ctr ++;
}
}

public void printnum()
{
for(int i=0; i<values.length ; i ++)
{
JOptionPane.sho wMessageDialog( null,"Display the numbers." + values[i]);

}
}

public void add( )
{
Are we still going the right direction here?
Oct 26 '06 #14
johnathan
12 New Member
am sorry, but i am.
that is what i came up with for the read statement, now following that i need help in the addition method, note please take a look at the program also.
Oct 26 '06 #15
johnathan
12 New Member
i need hepl with the addition and subtraction method.above you will see what i did so far.

also how do you declare a class within a class method. example.
the program would be:

example test=new example()
example test2=new example()
example test3=new example()

test.readinfo() ;
test2.readinfo( )
test3(test,test 2) HOW IS THIS REPRESENTED INT THE CLASS METHOD

public void add( WHAT GOES IN HERE)



THANKS FOR HELPING.
Oct 27 '06 #16
johnathan
12 New Member
Is This Correct.



public void add( examplexx a, examplexx b)
{
int carry=0;
int sum=0;

for(int i=0; i<values.length ; i ++)
{
sum=carry + values.length + values.length;


if( sum >=10)
{
sum= sum-10;
carry =1;
}
else
{
carry =0;
}

}
JOptionPane.sho wMessageDialog( null, "The final sum is . " + sum);
}
Oct 28 '06 #17
r035198x
13,262 MVP
Is This Correct.



public void add( examplexx a, examplexx b)
{
int carry=0;
int sum=0;

for(int i=0; i<values.length ; i ++)
{
sum=carry + values.length + values.length;


if( sum >=10)
{
sum= sum-10;
carry =1;
}
else
{
carry =0;
}

}
JOptionPane.sho wMessageDialog( null, "The final sum is . " + sum);
}
All I can say is this depends on where the method is. If the method is the number class (which in this case is examplexx?) then the method signature should be
Expand|Select|Wrap|Line Numbers
  1. public examplexx add(examplexx a)
. This is how I think you should be doing it as you could tell for my draft method for add that I did above(If you looked at it).

Now your method is taking in two objects a and b and doing absolutely nothing with them?
Oct 30 '06 #18
r035198x
13,262 MVP
Needless for me to point out that values is not defined in your method and so the method will not compile anyway.
Oct 30 '06 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5976
by: KellyH | last post by:
Hi, I hope someone can point me in the right direction. I'll get it out of the way: Yes, I am a college student. No, I am not looking for anyone to do my homework, just looking for help. I have been reading this ng all semester, and found it very helpful. I just have a stupid problem going on right now. Here's the project: We have to make a little frame with a text field, where the user inputs a number, and a text area where a...
6
1707
by: Markus Dehmann | last post by:
I have n sets of elements. I want to find elements that occur more than once in more than one set. Maybe the following example shows what I mean: S1 = {1,2,3,2,4} S2 = {2,2,4,5,4} S2 = {2,5,2} The algorithm should find that the "2" occurs more than once in S1, S2, and
5
2216
by: akameswaran | last post by:
Disclaimer - I recognize this is not a practical exercise. There are many implementations around that would do the job better, more efficiently (Meaning in C) or whatever. I caught some thread about sorting and started thinking about shell sort.... and as part of my trying to pythonise my mind and break my java mindset So I decided to tackle this old school problem with the python mindset.
7
6444
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are now thown out of the array released properly by the CLI?
168
7307
by: broeisi | last post by:
Hello, Is there a way in C to get information at runtime if a processor is 32 or 64 bit? Cheers, Broeisi
14
1777
by: ablock | last post by:
I have an array to which i have a added a method called contains. I would like to transverse this array using for...in...I understand fully that for...in is really meant for Objects and not Arrays, but I purposely had this array filled unsequentially because the key for the array is meant to act as an ID which has a contextual meaning in my script. The problem, of course, is that for...in also returns my method 'contains' as one of the...
3
2570
by: hamishd | last post by:
What is the best way to store large arrays of numbers (eg, 4-byte integers)? Say I want to store an array of 1billion 4-byte integers.. If my computer has 4gB memory, then is this possible? int Large_Array; This will cause a "stack overflow" when i try and execute. How can I do this?
1
1266
by: JinFTW | last post by:
Ok so I had to develop a class in which I needed to count the number of times someone enters in a number from a selected group of numbers from 1 to 100. In this case we're talking about groups of 10. Since I'm not very good with arrays (it was advised I use an array of counters, but since my professor has yet to teach us do so, that wouldn't really work anyway). So I decided to get creative and do it this way (not finished yet, only worked up to...
151
8141
by: istillshine | last post by:
There are many languages around: C++, JAVA, PASCAL, and so on. I tried to learn C++ and JAVA, but ended up criticizing them. Is it because C was my first programming language? I like C because, comparatively, it is small, efficient, and able to handle large and complex tasks. I could not understand why people are using and talking about other programming languages.
0
10346
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9173
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.