hi i dont know if this is the right place to be asking this but im trying to create a small program in java that can calculate the area of a square and then of multiple squares if the user enters the number of squares and the size increment of the squares,i.e.
// Get Length(L)
System.out.print("What is the length of the square: ?");
L = data_input.nextDouble();
// Get Number of square areas to calculate(N)
System.out.print("How many squares do you want to calclate: ?");
N = data_input.nextDouble();
//Get Square size increment(I
System.out.print("Please enter the square size increment: !");
I = data_input.nextDouble()
just hoping someone can help me to get the output correctly so that it shows the amount of square areas corresponding to N and that the L in each case increases by the amount corresponding with I, thanks in advance if anyone can help me, will be hugely appreciated. thanks
17 1893
you have the basis of the program so why not create a simple test class, read in some data and then format the output until it meets your requirements?
hi i dont know what those things are, my problem specificaly is how to make it so that the output calculates the amount of squares and by the size increment based on user input, thanks anyway.
anybody got any ideas of how i would do this, i know i have to create an array but i dont know what to do after that.
you have the basis of the program so why not create a simple test class, read in some data and then format the output until it meets your requirements?
hi i dont know what those things are
Well if you do not know how to even compile your code to make a class to run I am not sure any one here can help you.
ok so i thought this was a place to get help for a problem with java, which is why i asked and gave speciific details, im not asking about how to compile im asking about my problem with the array,<Removed by moderator>
ok so i thought this was a place to get help for a problem with java, which is why i asked and gave speciific details, im not asking about how to compile im asking about my problem with the array,<Removed by moderator>
Well no need for obscenities.
Just create a class and put in a main method and the code you posted earlier and let's see how it looks.
ok sorry about that but his post aggrevated as it was totally uneccessary and didnt help at all, i know you say just create a class with the main method, my problem is what the main method should be, obviously the equation for the area is (L*L) but how do i work the I and N into it to get what I want?
ok sorry about that but his post aggrevated as it was totally uneccessary and didnt help at all, i know you say just create a class with the main method, my problem is what the main method should be, obviously the equation for the area is (L*L) but how do i work the I and N into it to get what I want?
-
-
public class MyProgram {
-
public static void main(String[] args) {
-
//You program logic goes here
-
}
-
}
-
Now you just write your logic in the main method.
ok i think the problem here is that im not using the proper terms to explain what i mean. i know how to create a class and how to create methods, i dont know how get it so that there are N(determined by user) amount of square areas in the ouput, and that the L in (L*L) is increased each time by I (determined by user ). Its the actual coding of this, that i dont know how to do.
ok i think the problem here is that im not using the proper terms to explain what i mean. i know how to create a class and how to create methods, i dont know how get it so that there are N(determined by user) amount of square areas in the ouput, and that the L in (L*L) is increased each time by I (determined by user ). Its the actual coding of this, that i dont know how to do.
If you have one square of side size n then area is
If you have N squares then the total area is - double totalArea = N * n * n;
L - the size of the side of the initial square
N - the amount of squares that need to be calculated
I - is the increment value that the L is increased by for each square
so if the user enters L=3, N=3, I=2
then the program should output
1st square area = 9 (3*3)
2nd square area = 25 (5*5)
3rd square area = 49 (7*7)
i suppose i shud of put this in the original post as to avoid the confusion
L - the size of the side of the initial square
N - the amount of squares that need to be calculated
I - is the increment value that the L is increased by for each square
so if the user enters L=3, N=3, I=2
then the program should output
1st square area = 9 (3*3)
2nd square area = 25 (5*5)
3rd square area = 49 (7*7)
i suppose i shud of put this in the original post as to avoid the confusion
-
-
double area = 0;
-
int L = 3;
-
int N = 3;
-
int I = 2;
-
for(int i = 0 ; i < N; i ++) {
-
area = area + (L * L);
-
L = L + I;
-
}
-
System.out.println(area);
-
thanks mate ill try that out it looks similar to what i thought i had to do, thanks very much
thanks mate ill try that out it looks similar to what i thought i had to do, thanks very much
Let us know how it goes.
- {
-
static Scanner data_input = new Scanner(System.in);
-
-
// Method to calculate the area of a square
-
static void square(String [] args)
-
{
-
int l, n, i, t, result = 0;
-
boolean quit;
-
-
// Get the length
-
System.out.print("Enter the length of a side of the square: ");
-
l = data_input.nextInt();
-
-
while(l <=0)
-
{
-
-
// Output error message
-
System.out.println("Length must be greater than 0");
-
-
// Get length
-
System.out.print("Enter the length: ");
-
l = data_input.nextInt();
-
}
-
// Get the number of squares
-
System.out.print("Enter the number of squares you wish to calculate: ");
-
n = data_input.nextInt();
-
-
if (n <=0)
-
{
-
System.out.println("That number was not valid:");
-
quit = true;
-
-
// Get the number of squares
-
System.out.print("Enter the number of squares you wish to calculate: ");
-
n = data_input.nextInt();
-
}
-
-
// Get the Increment
-
System.out.print("Enter the size increment: ");
-
i = data_input.nextInt();
-
-
if (i <=0)
-
{
-
System.out.println("That number was not valid:");
-
quit = true;
-
-
// Get the Increment
-
System.out.print("Enter the size increment: ");
-
i = data_input.nextInt();
-
}
-
-
// Add the numbers
-
-
for(t = 0 ; t < n; t++ )
-
{
-
result = (l * l);
-
// Display the result
-
System.out.print(l + " * ");
-
System.out.print(l + " = ");
-
System.out.println(result);
-
l = l + i;
-
}
-
-
-
-
}
-
this is how my code looked in the end and it worked perfectly, i used the array/loop that you gave me, it just needed slight rearrangement, thanks
this is how my code looked in the end and it worked perfectly, i used the array/loop that you gave me, it just needed slight rearrangement, thanks
Good to hear that .
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Nicholas Pappas |
last post by:
Hello all.
I am trying to write a Java3D loader for a geometry file from a
game, which has Unicode characters (Korean) in it. I wrote the loader
and it works in Windows, but I recently brushed...
|
by: Sateesh |
last post by:
Hi,
I am a beginner in Python, and am wondering what is it about the indentation
in Python, without which python scripts do not work properly.
Why can't the indentation not so strict so as to give...
|
by: mr.iali |
last post by:
Hi Everyone
I would like to get into software developent using a programming
language like c++, java or pl/sql for oracle.
I have no idea where to start from. Which language is there more...
|
by: dh.evolutionnext |
last post by:
Hey, I am an instructor and I have an XML class coming up. I would just
like to know a good, easy, and intuitive XML editor that does
validating, code completion, etc. I usually use NetBeans but...
|
by: redefined.horizons |
last post by:
I've traditionally been a Java developer, although I play around with
LISP. I recently migrated to Linux and I was exploring Mono as an
option for development on Linux. However, I've had some...
|
by: wellstone9912 |
last post by:
Java programmers seem to always be whining about how confusing and
overly complex C++ appears to them. I would like to introduce an
explanation for this. Is it possible that Java programmers...
|
by: John Salerno |
last post by:
I know there's a request for a good IDE at least once a week on the ng,
but hopefully this question is a little different. I'm looking for
suggestions for a good cross-platform text editor (which...
|
by: BillJosephson |
last post by:
Hi all. I am trying to use jEdit, but can't seem to download
any plugins. I go to Plugin Manager, and select Download
options. I update the mirro and can see lots of servers.
I select the first...
|
by: Bob Palank |
last post by:
I'm considering using VJ# in a first programming course in addition to or in
place of
JBuilder and the J2SE. Given install problems other students have had, VJ#
seems like a nice alternative.
I...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |