Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Multiplying ints stored as an array
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
claytonrichards




PostPosted: Wed Jan 13, 2010 8:47 pm   Post subject: Multiplying ints stored as an array

i'm trying to make a calculator. the user enter numbers that are stored in an array. the inputs can range from 1 to 1000. i tried but i can only get the first 3 inputs to multiply.
please help

x is set to 3 right now in askData but it has to work no matter what the value of x is (eg. it could be 100, 5, 6 or whatever)

code:

// The "Calc" class.
import java.awt.*;
import hsa.Console;

public class Calc
{

static Console c;
static int total, total2, total3;
static final int TOTAL = 100;
static int[] numDouble = new int [TOTAL];
static int line = 0;


public static void askData ()
{
for (int x = 0 ; x < 3 ; x++)
{
c.print ("input= ");
numDouble [line] = c.readInt ();
line++;
}
}


public static void displayData ()
{
int answer;
int nums;

for (int y = 1 ; y < line ; y = y + 2)
{
for (int i = 0 ; i < line ; i = i + 2)
{
total = numDouble [i] * numDouble [y];
}
}
total = total * numDouble [0];
c.print ("total " + total);

}



public static void main (String[] args)
{
c = new Console ();
askData ();
displayData ();
// Place your program here. 'c' is the output console
} // main method
} // Calc class
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Wed Jan 13, 2010 10:29 pm   Post subject: RE:Multiplying ints stored as an array

In the future, please describe the exact nature of the problem you're having. Particularly useful is sample input/output if your program will run, and a compiler error message if it will not.

The problem seems to be that your displayData() method is doing some very...interesting....calculation to show the products.

Think about it again. Draw it out on paper. Think about exactly what you want to happen with the numbers. Find a simple way of explaining what you want to do, simple enough for a child to understand. Ignore your current method while doing so.

Then and only then, translate this explanation from English to Java.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: