473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to print off answers from For loops

I am writing a program that I have to take the length of a rectangle (1-10) and multiply them by the width(1-10) I am using a for loop and this is what I have so far
Expand|Select|Wrap|Line Numbers
  1.   public class area
  2.   {
  3.   public static void main(Strings args[])
  4.   {
  5.   int height;
  6.   int width;
  7.   int area;
  8.   int i;
  9.   int e;
  10.   for (i=1; i>=11; i++);
  11.   height = i;
  12.   for (e=1; e>=11; e++);
  13.   width = e;
  14.   (area) = (height) * (width);
  15.   System.out.print (area);}
  16. }
  17.  
the error is in line 14 and it is saying "variable height might not have been initialized."
Dec 15 '10 #1
1 1561
Dheeraj Joshi
1,123 Expert 1GB
First of all the two for loops do not make any sense.

Expand|Select|Wrap|Line Numbers
  1. for (i=1; i>=11; i++);
  2. height = i;
  3. for (e=1; e>=11; e++);
  4. width = e;
  5.  
If you put the semi colon at the end of the for loop, loop will be terminated it won't execute.

putting a semi colon at the end of for loop make
Expand|Select|Wrap|Line Numbers
  1. height = 1
So in the next loop even width will be set to 1 (Remember you placed a semi colon to the second for loop as well).
Expand|Select|Wrap|Line Numbers
  1. width=1;
  2.  
So area is also 1.

Also change

Expand|Select|Wrap|Line Numbers
  1. public static void main(Strings args[])
  2.  
to
Expand|Select|Wrap|Line Numbers
  1. public static void main(String args[])
  2.  
Regards
Dheeraj Joshi
Dec 16 '10 #2

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

Similar topics

0
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return...
23
by: stewart.midwinter | last post by:
No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two...
4
by: dw | last post by:
Hello all. We're doing a site with teams and their members. We've got a page where we need to display people according to who belongs to a which team. I've heard that nested loops are bad, but...
5
by: Jason | last post by:
Hello, I am working on a website which uses forms to fill in a few answers to questions. Does anybody know a javascript that prints only the answers (i.e. the forms) and not the whole page? I...
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
3
by: tzuriel | last post by:
Hello all, I think nested loops will do what I want, but I can't seem to get them right. I have two tables, members and casts. I run a query as follows: $sql_query="SELECT DISTINCT...
6
by: Wijaya Edward | last post by:
Can we make loops control in Python? What I mean is that whether we can control which loops to exit/skip at the given scope. For example in Perl we can do something like: OUT: foreach my $s1...
4
by: Pyenos | last post by:
#!/usr/bin/python #################################################### # answers.py --- A simple answer bot # Copyright (C) 2006 Logan Lee # # MESSAGE: # # This program is a simple...
1
by: javedna | last post by:
Can PHP help with the following as I have tried in the MYSQL Forums and cant get any help Thanks Nabz ---------------------------------------- Hi I am developing a PHP MYSQL questionnaire...
1
by: tqlam | last post by:
I have a text file with Questions and Answers like below. I wrote a script in perl to search a question(s), if match Q's, then print Answers up to End_Q#. Can someone here help me in printing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.