473,378 Members | 1,156 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,378 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 2463
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.