| | |
half diamond output in java
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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.
•
•
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,840
Reputation:
Solved Threads: 503
•
•
•
•
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
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'); } }
![]() |
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
Views: 869 | Replies: 13
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application apps arguments array arrays automation awt binary bluetooth businessintelligence busy_handler(null) card chat class classes client code collision component constructor database draw eclipse error event eventlistener exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me jar java javafx javamicroeditionuseofmotionsensor javaprojects jmf jni jpanel jtree julia link linux list loop machine map method methods mobile netbeans newbie nls number object oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms socket sort sortedmaps sql string swing test textfield threads time tree unlimited utility webservices windows






