Hey,
I'm having trouble with an assignment and I need some help.
basically, the assignment is the same as the from the following link:
http://www.thescripts.com/forum/thread607498.html
However, there is one major exception: The pattern is reversed. Here is what it looks like:
If the user types "3", your program should produce the following output:
***
**
*
If the user types "9", your program should produce:
*********
********
*******
******
*****
****
***
**
*
I found out how to do the other pattern of my own but I am having trouble figuring out how to flip it.
Here is my code so far:
------------------------------------------------------------------
import java.io.*;
public class MagicPrinter
{
public static void main(String[] args)
throws java.io.IOException
{
String s1, s2, s3, total;
int num, minnum;
char a = 'a';
String star = "*";
total = "";
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.print("How many lines? ");
s1 = br.readLine();
num = Integer.parseInt(s1);
minnum = 1;
do
{
total = total + star;
minnum++;
System.out.println(total);
}
while(minnum <= num);
}
}
----------------------------------------------------------------
Any help would be apprecitated. Thanks.
7 2101
Hey,
I'm having trouble with an assignment and I need some help.
basically, the assignment is the same as the from the following link: http://www.thescripts.com/forum/thread607498.html
However, there is one major exception: The pattern is reversed. Here is what it looks like:
If the user types "3", your program should produce the following output:
***
**
*
If the user types "9", your program should produce:
*********
********
*******
******
*****
****
***
**
*
I found out how to do the other pattern of my own but I am having trouble figuring out how to flip it.
Here is my code so far:
------------------------------------------------------------------
import java.io.*;
public class MagicPrinter
{
public static void main(String[] args)
throws java.io.IOException
{
String s1, s2, s3, total;
int num, minnum;
char a = 'a';
String star = "*";
total = "";
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.print("How many lines? ");
s1 = br.readLine();
num = Integer.parseInt(s1);
minnum = 1;
do
{
total = total + star;
minnum++;
System.out.println(total);
}
while(minnum <= num);
}
}
----------------------------------------------------------------
Any help would be apprecitated. Thanks.
Algorithm:
Assuming my input is 7 - while( input not equal to 0 )
-
-
Print the ' * ' input times...
-
Create new line...
-
Decrement the input...
Sukatoa (Shadow Shaman)
Algorithm:
Assuming my input is 7 - while( input not equal to 0 )
-
-
Print the ' * ' input times...
-
Create new line...
-
Decrement the input...
Sukatoa (Shadow Shaman)
I tried this and it is giving me the output
*
*
*
*
*
*
*
*
*
This is what I typed:
while (num != 0)
{
System.out.println(star);
num--;
}
when I also try:
while (num !=0)
{
total = total + star;
System.out.println(total);
num--;
}
I get the same pattern I had to begin with. Maybe I'm just unsure of what you meant by print '*' input times...
I tried this and it is giving me the output
*
*
*
*
*
*
*
*
*
This is what I typed:
while (num != 0)
{
System.out.println(star);
num--;
}
when I also try:
while (num !=0)
{
total = total + star;
System.out.println(total);
num--;
}
I get the same pattern I had to begin with. Maybe I'm just unsure of what you meant by print '*' input times...
print '*' input times is = Print the asterisk many times depend on the input, if my input is currently 7, then print the asterisk 7 times in the same line...
Maybe you forgot this,
What is the difference between - System.out.print("Something");
and - System.out.println("Something");
If you can differentiate that, then proceed... If you are not sure, make some experiments about the two...
Update us.
Sukatoa
print '*' input times is = Print the asterisk many times depend on the input, if my input is currently 7, then print the asterisk 7 times in the same line...
Maybe you forgot this,
What is the difference between - System.out.print("Something");
and - System.out.println("Something");
If you can differentiate that, then proceed... If you are not sure, make some experiments about the two...
Update us.
Sukatoa
I know the difference between the methods; println returns a new line after completing while print prints subsequent information on the same line. I played around with many different things and this is what I ended with
while (num != 0)
{
total = total + star;
System.out.print(total);
System.out.print("");
num--;
}
When imputing 9 I get the required number of stars but on the same line. When i use println for the second method I just get the same result I had to begin with.
You must understand the code below before you attempt to try it, if you don't follow my instructions, later you will be dependent from the others....
I hope you will understand this.... - public class demo{
-
public static void main(String sukatoa[]){
-
int input = new java.util.Scanner(System.in).nextInt();
-
while(input > 0){
-
System.out.println();
-
for(int x=0;x<input;x++){
-
System.out.print("*");
-
}input--;
-
}System.out.println();
-
}
-
}
The code i've posted above will be deleted after a few minutes by the moderator... Please, read the book carefully next time...
Try to make have some experiments... Later you will come-up an idea...
Worrying
Sukatoa.
You must understand the code below before you attempt to try it, if you don't follow my instructions, later you will be dependent from the others....
I hope you will understand this.... - public class demo{
-
public static void main(String sukatoa[]){
-
int input = new java.util.Scanner(System.in).nextInt();
-
while(input > 0){
-
System.out.println();
-
for(int x=0;x<input;x++){
-
System.out.print("*");
-
}input--;
-
}System.out.println();
-
}
-
}
The code i've posted above will be deleted after a few minutes by the moderator... Please, read the book carefully next time...
Try to make have some experiments... Later you will come-up an idea...
Worrying
Sukatoa.
Thank You. I now see. So first comes the space and then the input, along with the corresponding amount of stars. The input is then decreased by one and a new line is then printed whereby the decreased amount of stars follows the same process until it reaches 1. At least I think I've now got it.
Thank You. I now see. So first comes the space and then the input, along with the corresponding amount of stars. The input is then decreased by one and a new line is then printed whereby the decreased amount of stars follows the same process until it reaches 1. At least I think I've now got it.
Nice flow...
No probz.. ;-)
Sukatoa...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brian |
last post by:
Hi all... This question is more for the GURUs out there. It is not a
question on how to do something, but why it happens, and I am trying to
figure out if there is a pattern. I am using IE, but...
|
by: qazmlp |
last post by:
Builder pattern seem to suit my requirements perfectly except in one
case
as described below.
I have used the same example diagram that is used in GOF Design
pattern book, to explain the problem...
|
by: Alicia Roberts |
last post by:
Hello everyone, I have been researching the Singleton Pattern. Since the
singleton pattern uses a private constructor which in turn reduces
extendability, if you make the Singleton Polymorphic...
|
by: Ian Pilcher |
last post by:
The more I think about pointers, the more my head hurts.
From what I can tell, nothing in the standard guarantees that pointer
assignment preserves bit patterns.
Section 6.5.16.1, paragraph 2,...
|
by: Marcel Hug |
last post by:
Hi NG !
I have already written a task about MVC and I tried to get the best
informations together.
I would like to implement the MVC pattern and it work on the way I did it.
At first i know the...
|
by: Eric |
last post by:
I am implementing a variation on the Singleton design pattern, that
allows up to 8 objects of a class to be instantiated, and returns a
null pointer for anything more than 8.
I am running into a...
|
by: dave.dolan |
last post by:
Basically I'd like to implement the composite design pattern with leaves that
are either of reference or value types, but even using generics I can't seem
to avoid boxing (using ArrayList or...
|
by: lars.uffmann |
last post by:
Hi everyone!
I am debugging a big piece of code on the search for memory leaks,
using g++ under suse 9.3.
Since I'm trying to eliminate ALL memory leaks, I now stumbled upon a
class foo that is...
|
by: JoeC |
last post by:
I have read books and have ideas on how to create objects. I often
create my own projects and programs. They end up getting pretty
complex and long. I often use objects in my programs they are...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |