| | |
half diamond output in java
![]() |
•
•
Join Date: Jun 2009
Posts: 8
Reputation:
Solved Threads: 0
hi im having problem on how to make the output of my programme like this:
if you enter a number: (EVEN)
*
**
***
*****
If you enter a number
ODD)
*****
****
***
**
*
im always having an output of:
(EVEN)
*
**
***
****
(ODD)
*****
****
***
**
*
I hope somebody will haelp me:
here is my code:
import java.io.*;
public class del
{
public static void main(String[]args)throws IOException
{
BufferedReader IN = new BufferedReader(new InputStreamReader(System.in));
int a, c, d;
String b, e, f;
do{
System.out.println("Enter name:");
f = IN.readLine();
System.out.println("Enter a number:");
b = IN.readLine();
d = Integer.parseInt(b);
if(d%2==0)
{
for(a=d;a>=0;a--)
{
for(c=a;c<d;c++)
{
System.out.print(f);
}
System.out.println(" ");
}
}
else
{
for(a=0;a<=d;a+=1)
{
for(c=a;c<d;c++)
{
System.out.print(f);
}
System.out.println(" ");
}
}
System.out.print("Try Again?:");
e = IN.readLine();
}while(e.charAt(0)=='y'||e.charAt(0)=='Y');
}
}
if you enter a number: (EVEN)
*
**
***
*****
If you enter a number
ODD)*****
****
***
**
*
im always having an output of:
(EVEN)
*
**
***
****
(ODD)
*****
****
***
**
*
I hope somebody will haelp me:
here is my code:
import java.io.*;
public class del
{
public static void main(String[]args)throws IOException
{
BufferedReader IN = new BufferedReader(new InputStreamReader(System.in));
int a, c, d;
String b, e, f;
do{
System.out.println("Enter name:");
f = IN.readLine();
System.out.println("Enter a number:");
b = IN.readLine();
d = Integer.parseInt(b);
if(d%2==0)
{
for(a=d;a>=0;a--)
{
for(c=a;c<d;c++)
{
System.out.print(f);
}
System.out.println(" ");
}
}
else
{
for(a=0;a<=d;a+=1)
{
for(c=a;c<d;c++)
{
System.out.print(f);
}
System.out.println(" ");
}
}
System.out.print("Try Again?:");
e = IN.readLine();
}while(e.charAt(0)=='y'||e.charAt(0)=='Y');
}
}
Welcome sympatiko.
Use BB code tags. Your source code must be surrounded with bb code tags. Read How to wrap up source code with bb code tags?
You are near to the solution. Keep it up.
Use BB code tags. Your source code must be surrounded with bb code tags. Read How to wrap up source code with bb code tags?
You are near to the solution. Keep it up.
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Jun 2009
Posts: 8
Reputation:
Solved Threads: 0
•
•
•
•
Welcome sympatiko.
Use BB code tags. Your source code must be surrounded with bb code tags. Read How to wrap up source code with bb code tags?
You are near to the solution. Keep it up.
•
•
Join Date: Jan 2008
Posts: 3,765
Reputation:
Solved Threads: 492
•
•
•
•
im a newbie in programming,,i cant understand those kind of coding,,can you please solve my problem if you know?
[code]
// paste code or pattern here
[/code]
Note the difference (with code tags):
Java Syntax (Toggle Plain Text)
* * * *
Without code tags:
*
*
*
*
Please repost using code tags, as explained above. Again, do this to retain spacing. Thanks.
[code]
// paste code or pattern here
[/code]
•
•
Join Date: Jun 2009
Posts: 8
Reputation:
Solved Threads: 0
•
•
•
•
hi im having problem on how to make the output of my programme like this:
if you enter a number: (EVEN)
*
**
***
*****
If you enter a numberODD)
*****
****
***
**
*
im always having an output of:
(EVEN)
*
**
***
****
(ODD)
*****
****
***
**
*
I hope somebody will haelp me:
here is my code:
import java.io.*;
public class del
{
public static void main(String[]args)throws IOException
{
BufferedReader IN = new BufferedReader(new InputStreamReader(System.in));
int a, c, d;
String b, e, f;
do{
System.out.println("Enter name:");
f = IN.readLine();
System.out.println("Enter a number:");
b = IN.readLine();
d = Integer.parseInt(b);
if(d%2==0)
{
for(a=d;a>=0;a--)
{
for(c=a;c<d;c++)
{
System.out.print(f);
}
System.out.println(" ");
}
}
else
{
for(a=0;a<=d;a+=1)
{
for(c=a;c<d;c++)
{
System.out.print(f);
}
System.out.println(" ");
}
}
System.out.print("Try Again?:");
e = IN.readLine();
}while(e.charAt(0)=='y'||e.charAt(0)=='Y');
}
}
if even:
*
****
******
if odd:
******
****
*
so now,,give me the code,,how to make that
Use bb code tag. Read this - How to use code tag?
Failure is not fatal, but failure to change might be. - John Wooden
Java Syntax (Toggle Plain Text)
import java.io.*; public class p { public static void main(String[]args)throws IOException { BufferedReader IN = new BufferedReader(new InputStreamReader(System.in)); int a, c, d,cnt; String b, e, f; do{ System.out.println("Enter name:"); f = IN.readLine(); System.out.println("Enter a number:"); b = IN.readLine(); d = Integer.parseInt(b); if(d%2==0) { for(a=1;a<=d;a++) { if(a==1) cnt=1; else cnt=a*2; for(c=1;c<=cnt;c++) { System.out.print(f); } System.out.println(" "); } } else { for(a=d;a>=1;a--) { if(a==1) cnt=1; else cnt=a*2; for(c=1;c<=cnt;c++) { System.out.print(f); } System.out.println(" "); } } System.out.print("Try Again?:"); e = IN.readLine(); }while(e.charAt(0)=='y'||e.charAt(0)=='Y'); } }
Failure is not fatal, but failure to change might be. - John Wooden
![]() |
Similar Threads
- Making A Java Compiler... In Java (Java)
- Problem with printing(showing) output in Java (Java)
- Need help in a appending output from a java pgm in an Existing Excel sheet (Java)
- java printing patterns (Java)
- What the problem this java program output??? (Java)
- problem with a java program (Java)
- Diamond??? (C++)
- Python with Java? (Python)
Other Threads in the Java Forum
- Previous Thread: Help needed to develop an application
- Next Thread: Need help with character movement on slanted surfaces
| Thread Tools | Search this Thread |
911 addball addressbook android api applet application apps array automation awt binary bluetooth businessintelligence busy_handler(null) button card class client code collision component constructor crashcourse css csv database draw eclipse ee error eventlistener exception fractal free game gis givemetehcodez graphics gui html ide image integration j2me japplet java javaarraylist javadoc javafx javamicroeditionuseofmotionsensor javaprojects jni jpanel jtree julia jvm linux loan map method migrate mobile netbeans objects oracle oriented phone physics plazmic problem program programming project projects radio recursion replaydirector reporting scanner se server service set sharepoint smart sms software sortedmaps sql swing test textfield threads tree trolltech ubuntu unlimited utility windows






