473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

program on character

Hello,
i am new to java and i am not able to do the following program. If anybody can help me it will be very helpful to me. the program is to be done without using array . the program question is

" use a method named design which states a integer argument between 1 and 9 and print the following matter as shown below

ex: for integer argument = 4
Expand|Select|Wrap|Line Numbers
  1. abcdcba
  2. abc cba
  3. ab   ba 
  4. a     a
  5. ab   ba
  6. abc cba
  7. abcdcba
Oct 27 '07 #1
2 2467
Ganon11
3,652 Expert 2GB
Looks like you'll have to use some tricky manipulation of for loops. A hint: Just because most for...loops use an int to control, doesn't mean you can't use another variable type...like a char. For instance, this loop prints the alphabet:

Expand|Select|Wrap|Line Numbers
  1. for (char ch = 'a'; ch <= 'z'; ch++)
  2.    System.out.print(ch);
Oct 27 '07 #2
JosAH
11,448 Expert 8TB
Hello,
i am new to java and i am not able to do the following program. If anybody can help me it will be very helpful to me. the program is to be done without using array . the program question is

" use a method named design which states a integer argument between 1 and 9 and print the following matter as shown below

ex: for integer argument = 4
Expand|Select|Wrap|Line Numbers
  1. abcdcba
  2. abc cba
  3. ab   ba 
  4. a     a
  5. ab   ba
  6. abc cba
  7. abcdcba
If you interpret that little square a an x,y grid with 0,0 in the middle of that square,
and the square has size 2*N-1 (N given by the user) you can loop in both directions
in the range [-N+1, N-1] (e.g. N == 4, loop in the range [-3, 3]).

Ignoring those spaces for the moment you have to print the character
'a'+N-1-abs(x), i.e. the y value has nothing to do with it.

For the spaces, have a look at the upper right quadrant: if abs(y) <= 2-abs(x) you
must print a space instead. (it's simple linear algebra).

You can put two nested loops together (one for x and one for y) and apply the
logic I sketched above in the body of the innermost loop.

kind regards,

Jos
Oct 27 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Ling Lee | last post by:
Hello. I'm trying to write a small program that lets you put in a number as an integer and then it tells you the textuel representation of the number. Like if your input is 42, it will say...
11
by: James Hu | last post by:
This program is long. I don't really want to bore everyone with the details, but it handles wierd cases like: /\ * this is a comment *\ / #define FOO ??/* this is not a comment */ char...
54
by: bnp | last post by:
Hi, I took a test on C. there was an objective question for program output type. following is the program: main() { char ch; int i =2;
40
by: findmadhav | last post by:
I need a program in C (something like a TSR) which will automatically press the function key F6, say about every 5 seconds. Can anyone provide me with an exe of such a program? Thanks in advance.
8
by: Alvin | last post by:
Right. I`m using Dev-Cpp, and I`m working on a game at this time in SDL (http://libsdl.org), and I`ve come across this error: ------------------------------------------ main.c: In function...
10
by: yaniv.dg | last post by:
hi all, i'm bumping into smething very starnge its very simple code but from some reason the program is acting strange this is my code: #include<stdio.h> #include<conio.h> void main(void) {...
4
by: sulekhasweety | last post by:
Hi, can any one give a brief outline of the different stages in the execution of a C program , in terms of compilation, pre-processing, linking etc
35
by: hdsalbki | last post by:
hi everyone, I have below a small program to echo back what character the user types. It's working OK but prints a extra prompt between every character. what can I do? I'm new in C and my book is...
6
by: nickels | last post by:
Ok i already made a program that uses char and when someone enters a letter it will give them a conversion i made for that letter. That looks like this. import java.util.Scanner; public class...
13
by: Liang Chen | last post by:
Hope you all had a nice weekend. I have a question that I hope someone can help me out. I want to run a Python program that uses Tkinter for the user interface (GUI). The program allows me to type...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.