Welcome to Dream.In.Code
Become a Java Expert!

Join 150,138 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,269 people online right now. Registration is fast and FREE... Join Now!




While loops

 
Reply to this topicStart new topic

While loops, Beyond frustrated

j_delong
21 Aug, 2008 - 10:27 AM
Post #1

New D.I.C Head
*

Joined: 21 Aug, 2008
Posts: 8

I am trying to obtain input from user and with that information create a diamond. So far all I have is my class started, defined my variables and have asked for user input. Here is the part that gets frustrating....I don't really understand the whole concept of while loops and if/else statements and obviously I can't go any further with a solution. Can someone please guide me in the right direction with this one. This is what I have so far....now what?

java

public class Diamond
{
public static void main (String[] args) throws IO Exception
{
String blank "";
String symbol;
int numCount;
int lineCount = 0;
int width;
int newNum;
PrintWriter outFile;
BufferedReader in;

in=newBufferedReader(new InputStreamReader(System.in));
outFile = new PrintWriter(new FileWriter("diamond.out"));
outFile = new PrintWriter(System.out);
System.out.print("Enter a character to form a diamond");
symbol = in.readLine();
System.out.print("Enter a number for the width of the diamond");
width = in.readLine();
newNum=(width/2);

while (symbol !=null)
{
numCount = Integer.parseInt(symbol);
linecount = 0

User is offlineProfile CardPM
+Quote Post

Ak-Emm
RE: While Loops
21 Aug, 2008 - 11:59 AM
Post #2

New D.I.C Head
*

Joined: 18 Aug, 2008
Posts: 22



Thanked: 1 times
My Contributions
QUOTE(j_delong @ 21 Aug, 2008 - 11:27 AM) *

I am trying to obtain input from user and with that information create a diamond. So far all I have is my class started, defined my variables and have asked for user input. Here is the part that gets frustrating....I don't really understand the whole concept of while loops and if/else statements and obviously I can't go any further with a solution. Can someone please guide me in the right direction with this one. This is what I have so far....now what?

java

public class Diamond
{
public static void main (String[] args) throws IO Exception
{
String blank "";
String symbol;
int numCount;
int lineCount = 0;
int width;
int newNum;
PrintWriter outFile;
BufferedReader in;

in=newBufferedReader(new InputStreamReader(System.in));
outFile = new PrintWriter(new FileWriter("diamond.out"));
outFile = new PrintWriter(System.out);
System.out.print("Enter a character to form a diamond");
symbol = in.readLine();
System.out.print("Enter a number for the width of the diamond");
width = in.readLine();
newNum=(width/2);

while (symbol !=null)
{
numCount = Integer.parseInt(symbol);
linecount = 0




OhhhKy kinda different programing style compared to mine
Its actually Kinda straight forward if experimented frequently
more easier with Pascal

this might be a little unorthodox
but if you have a Casio CFX/FX 9860 G plus etc + Calc models look at the manual book on the programming section to help understand better with loops explains well detailed

i just stumbled accros this site
-----> http://www.cafeaulait.org/javatutorial.html#xtocid190365


might be useful


User is offlineProfile CardPM
+Quote Post

Martyr2
RE: While Loops
21 Aug, 2008 - 08:34 PM
Post #3

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Check out my blog entry about building shapes with loops. My examples take advantage of a for loop, but building it for the while loop will be very easy using my code.

It explains how the loops work, shows you some simple shapes like triangles and such and then eventually goes into the code for creating a diamond.

Feel free to lift what code you need and play with it. Just modify them to use the while loop if that is what your goal is to use.

The link is below...

Martyr2's Programming Underground - Building shapes with loops (In java)

Hope this helps you out. Enjoy! smile.gif
User is offlineProfile CardPM
+Quote Post

yooxygen
RE: While Loops
22 Aug, 2008 - 07:52 PM
Post #4

New D.I.C Head
*

Joined: 20 Jan, 2008
Posts: 15


My Contributions
nice !! smile.gif
User is offlineProfile CardPM
+Quote Post

j_delong
RE: While Loops
25 Aug, 2008 - 04:48 AM
Post #5

New D.I.C Head
*

Joined: 21 Aug, 2008
Posts: 8

QUOTE(Martyr2 @ 21 Aug, 2008 - 09:34 PM) *

Check out my blog entry about building shapes with loops. My examples take advantage of a for loop, but building it for the while loop will be very easy using my code.

It explains how the loops work, shows you some simple shapes like triangles and such and then eventually goes into the code for creating a diamond.

Feel free to lift what code you need and play with it. Just modify them to use the while loop if that is what your goal is to use.

The link is below...

Martyr2's Programming Underground - Building shapes with loops (In java)

Hope this helps you out. Enjoy! smile.gif



QUOTE(Martyr2 @ 21 Aug, 2008 - 09:34 PM) *

Check out my blog entry about building shapes with loops. My examples take advantage of a for loop, but building it for the while loop will be very easy using my code.

It explains how the loops work, shows you some simple shapes like triangles and such and then eventually goes into the code for creating a diamond.

Feel free to lift what code you need and play with it. Just modify them to use the while loop if that is what your goal is to use.

The link is below...

Martyr2's Programming Underground - Building shapes with loops (In java)

Hope this helps you out. Enjoy! smile.gif



QUOTE(j_delong @ 21 Aug, 2008 - 11:27 AM) *

I am trying to obtain input from user and with that information create a diamond. So far all I have is my class started, defined my variables and have asked for user input. Here is the part that gets frustrating....I don't really understand the whole concept of while loops and if/else statements and obviously I can't go any further with a solution. Can someone please guide me in the right direction with this one. This is what I have so far....now what?

java

public class Diamond
{
public static void main (String[] args) throws IO Exception
{
String blank "";
String symbol;
int numCount;
int lineCount = 0;
int width;
int newNum;
PrintWriter outFile;
BufferedReader in;

in=newBufferedReader(new InputStreamReader(System.in));
outFile = new PrintWriter(new FileWriter("diamond.out"));
outFile = new PrintWriter(System.out);
System.out.print("Enter a character to form a diamond");
symbol = in.readLine();
System.out.print("Enter a number for the width of the diamond");
width = in.readLine();
newNum=(width/2);

while (symbol !=null)
{
numCount = Integer.parseInt(symbol);
linecount = 0



User is offlineProfile CardPM
+Quote Post

JeroenFM
RE: While Loops
25 Aug, 2008 - 09:10 AM
Post #6

D.I.C Head
Group Icon

Joined: 30 Jun, 2008
Posts: 191



Thanked: 9 times
Dream Kudos: 100
My Contributions
The next step is obvious: complete your code, you're missing the bottom half or so.

Loops are easy:

java

while (boolean_expression) {
stuff();
}

for (int i = 0; i < 10; i++) {
stuff();
}



The top loop will first check boolean_expression, then if it evaluates to true, will execute what's between the curly brackets. It will then keep doing this until boolean_expression evaluates to false.

The bottom loop has a variable i which starts at 0, is incremented after each repetition of the loop (the i++ statement) and will keep doing so until i < 10 evaluates to false, which happens if i equals 10 or higher.

Clear enough?
User is offlineProfile CardPM
+Quote Post

j_delong
RE: While Loops
27 Aug, 2008 - 09:01 AM
Post #7

New D.I.C Head
*

Joined: 21 Aug, 2008
Posts: 8

I have successfully finished my diamond program. Thank you for all the help guys!!!


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:11AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month