| | |
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,805
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 |
-xlint actionlistener android api applet application array arrays automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html ide image integer j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux list mac main map method methods mobile myregfun netbeans notdisplaying number online printf problem program project qt recursion researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields threads time title tree tutorial-sample update variablebinding windows working xor






