| | |
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,813
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 |
account android api applet application array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) chat class classes client code columns component database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source plazmic print problem program programming project property recursion ria scanner search server set smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree webservices windows






