Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework
this week in the
Java in General
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Liutauras Vilda
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Devaka Cooray
Paul Clapham
Saloon Keepers:
Scott Selikoff
Tim Holloway
Piet Souris
Mikalai Zaikin
Frits Walraven
Bartenders:
Stephan van Hulst
Carey Brown
Forum:
Java in General
diamond pattern without parse.int (Someone help me T.T) :cry:
hansen wijaya
Greenhorn
Posts: 1
posted 13 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
import java.util.Scanner; public class Homework_5 { public static void main(String[] args) { System.out.print("Valid length of a side is between 1 and 10.\n"); int num;// Read a line of input(stars) from user. Scanner scan= new Scanner(System.in); // scanner reads from standard input. int input = -1; System.out.print("Enter the length of a side: "); input = scan.nextLine(); int c = 0; while (num < 1 || num > 10) { System.out.print("Error, out of valid range, only 1 to 10 allowed.\n"); System.out.print("Enter the length of a side: "); num = scan.nextLine(); } { // counting down int n1=num, countx=1; for (int i=n1; i >= 1;i--) //number of , keep on reducing { for (int j =1;j<i;j++) { System.out.print(" "); // number of spaces } System.out.print("*"); // print out the star if (c!=0) { for (int z = 1;z<=countx; z++) { System.out.print(" "); } System.out.print("*"); countx+=2; } System.out.println(); c++; } //counting up for (int i =2;i<=n1;i++) { for (int j =1;j<i;j++) { System.out.print(" "); } System.out.print('*'); if (c!=2) { for (int x=5;x<=countx;x++) { System.out.print(" "); } System.out.println("*"); } countx-=2; c--; } } } }[code=java]
[/code]
Lindsey Brooks
Ranch Hand
Posts: 58
I like...
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Here is my way of making a diamond:
public class patternc { public static void main(String args[]) { int numberofcolums = 1; int spaces = 11; for(int i=1;i<=11;i++) { for(int k=spaces; k>=0; k--) { System.out.print(" "); } for(int j=1; j<=numberofcolums; j++) { System.out.print("# "); } System.out.println(); if(i<6) { numberofcolums = numberofcolums+2; spaces = spaces-2; } else { numberofcolums = numberofcolums-2; spaces = spaces+2; } } } }
Norm Radder
Rancher
Posts: 5077
38
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can you show what the program does now and explain what you want it to do differently?
What problems are you having? If there are errors, copy the full text and paste it here.
Lindsey Brooks
Ranch Hand
Posts: 58
I like...
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
This was posted 5 years ago...
Norm Radder
Rancher
Posts: 5077
38
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yes, I missed that.
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
help with arrays program in java
how to complete this code?
Why my Array skips the first entry ?
Battleships - guys please help me out!
Displaying output for the given format
Thread Boost feature
More...