| | |
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,817
Reputation:
Solved Threads: 501
•
•
•
•
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
- Diamond??? (C++)
- 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)
- 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 |
6 @param actuate android api applet application arc array arrays automation balls binary bluetooth bold business byte c++ chat class client code codesnippet collections compare component coordinates database defaultmethod doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework hql html ide ideas image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list loop looping map method methods mobile mysql netbeans newbie nextline parameter php pong problem program programming project recursion recursive scanner sell server set sms sort sql string sun swing swt threads tree web websites windows






