Computer Science Canada
Programming C, C++, Java, PHP, Ruby, Turing, VB
Username:
Password:
Register
Wiki
Blog
Search
Turing
Chat Room
Members
making diamonds
Index
->
Programming, Java
->
Java Help
Author
Message
Prince
Posted:
Fri Feb 06, 2004 10:59 am
Post subject: making diamonds
i need help making the top part of a diamond... the purpose is to put in an odd integer (ex: 5) and it would print out a diamond...
so if u put in 5 it would look like this:
s*****
*******
s*****
ss***
sss* (the s is a space)
the stuff under the line ive got, its the top im struggling on... any suggestions?
code:
import java.awt.*;
import hsa.Console;
public class Star
{
static Console c;
public static void main (String [] args)
{
c = new Console ();
int size = 0;
int space = 1;
do
{
c.println ("Enter an odd number between 1 and 25: ");
size = c.readInt ();
}
while (size < 1 || size > 25);
c.println ("");
/* while (size>=1)
{
for (int a=1;a<space;a++)
*/
while (size >= 1)
{
for (int a = 1 ; a < space ; a++)
c.print (" ");
for (int b = 0 ; b < size ; b++)
c.print ("*");
c.println ("");
size -= 2;
space++;
}
}
}
Sponsor
Sponsor
rizzix
Posted:
Fri Feb 06, 2004 3:32 pm
Post subject: (No subject)
here's a pseudocode, that sortof works:
code:
int w = 9; // width of diamond
print repeat " " by w - ((w - 2) mod w); // might have to replace these
print repeat "*" by (w - 2) * 2; // two lines with better code
println;
for (int i = w - 1; i >= 0; i--) {
print repeat " " by w - (i mod w);
print repeat "*" by i * 2;
println;
}
Display posts from previous:
All Posts
1 Day
7 Days
2 Weeks
1 Month
3 Months
6 Months
1 Year
Oldest First
Newest First
Index
->
Programming, Java
->
Java Help
Page
1
of
1
[ 2 Posts ]
Jump to:
Select a forum
CompSci.ca
------------
- Network News
- General Discussion
General Forums
-----------------
- Hello World
- Featured Poll
- Contests
Contest Forums
-----------------
- DWITE
- [FP] Contest 2006/2008
- [FP] 2005/2006 Archive
- [FP] 2004/2005 Archive
- Off Topic
Lounges
---------
- User Lounge
- VIP Lounge
Programming
--------------
- General Programming
General Programming Forums
--------------------------------
- Functional Programming
- Logical Programming
- C
C
--
- C Help
- C Tutorials
- C Submissions
- C++
C++
----
- C++ Help
- C++ Tutorials
- C++ Submissions
- Java
Java
-----
- Java Help
- Java Tutorials
- Java Submissions
- Ruby
Ruby
-----
- Ruby Help
- Ruby Tutorials
- Ruby Submissions
- Turing
Turing
--------
- Turing Help
- Turing Tutorials
- Turing Submissions
- PHP
PHP
----
- PHP Help
- PHP Tutorials
- PHP Submissions
- Python
Python
--------
- Python Help
- Python Tutorials
- Python Submissions
- Visual Basic and Other Basics
VB
---
- Visual Basic Help
- Visual Basic Tutorials
- Visual Basic Submissions
Education
-----------
- Student Life
Graphics and Design
-----------------------
- Web Design
Web Design Forums
---------------------
- (X)HTML Help
- (X)HTML Tutorials
- Flash MX Help
- Flash MX Tutorials
- Graphics
Graphics Forums
------------------
- Photoshop Tutorials
- The Showroom
- 2D Graphics
- 3D Graphics
Teams
------
- dTeam Public
Style:
Appalachia
blueSilver
eMJay
subAppalachia
subBlue
subCanvas
subEmjay
subGrey
subSilver
subVereor
Search:
You can syndicate this boards posts using the file
backend.php
or view the
topic map using sitemap.php.
Terms of Use
|
Privacy Policy