473,406 Members | 2,378 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,406 software developers and data experts.

Displaying Information On The Screen

How can i write a program to display a number of series like the following:

56789
6789
789
89
9

Expand|Select|Wrap|Line Numbers
  1. public class displaying {
  2.  
  3.  
  4.    public static void main(String args[]){
  5.        int x,y,z;
  6.        for(x=0;x<5;x++){
  7.          for(y=5;y<10;y++){
  8.              z=x+y;
  9.              System.out.println(z);
  10.          }
  11.        }
  12.    }
  13. }
i have write the program but its not giving the desired output.Something is missing.Please can anyone tell what condition i required for the completion of the above problem.
Thank You....
Jan 9 '15 #1
1 1281
Frinavale
9,735 Expert Mod 8TB
Your program is supposed:
  • Start with to take a bunch of characters (56789)
  • Display all of the characters and then, on subsequent lines, continue to display the the characters after removing one from the right

In Java there are structures called Arrays that contain a group of things.

In your case you should have an array of characters that contains the values 56789. (You could also use an array of Numbers or Integer or anything else really)

So, after you populate your array, the array will look like this:
Expand|Select|Wrap|Line Numbers
  1.        --------------------- 
  2. data:  | 5 | 6 | 7 | 8 | 9 |
  3.        --------------------- 
  4. index:  [0] [1] [2] [3] [4] 
  5.  
Please note that the character "5" is in position/index 0 in the array.

With that in mind, this is how you would populate your array:
Expand|Select|Wrap|Line Numbers
  1. // creating an array variable to hold the information
  2. char[] anArray;
  3.  
  4. // allocates memory for 5 characters
  5. anArray = new char[5];
  6.  
  7. // initialize first element
  8. anArray[0] = '5';
  9. // initialize second element
  10. anArray[1] = '6';
  11. // and so forth
  12. anArray[2] = '7';
  13. anArray[3] = '8';
  14. anArray[4] = '9';
You can accomplish the same thing in less lines of code by doing the following:
Expand|Select|Wrap|Line Numbers
  1.   char[] anArray = {'5','6','7','8','9'};
  2.  
But it will result in the same thing as demonstrated above.

Now that you have an array, you can loop through the elements within it and display them on your screen.
Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args){
  2.   char[] anArray = {'5','6','7','8','9'};
  3.   for(int index=0; index<anArray.length; index++){
  4.     System.out.print(anArray[index]);
  5.   }
  6.   System.out.println('');
  7. }
  8.  
Now, I will leave it up to you to try and figure out how to print the array by removing the right item. (Hint: you can manipulate the index of the array that you start at while printing)

If you have a problem with it, post back here and I'll help you through it.

Please take a look at the links I've posted because they have very useful information in them.

-Frinny
Jan 12 '15 #2

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

Similar topics

1
by: Waguih Boctor | last post by:
Hi, I have a number of ASP pages where some JPGs and GIFs are displaying in the browser and some are not. I have included an excerpt from the HTML below. In this example, the gif file at the...
8
by: euang | last post by:
Hi, I have been using access 2000 for two years on WINDOWS NT to display dynamic aweb page using ASP My ISP has now changed to Windows 2003, and I am having major problems displaying...
1
by: Dave Posh | last post by:
I seem to be having a problem displaying time stored in mysql. The format stored in the database is 13:15:05. The database data type is time. I'm using asp vbscript and sql to retrieve the time...
2
by: Joe Price | last post by:
Hi chaps I've got an XML file, within that file i've embedded html code using the <!]> tag I'm displaying that xml file through a browser using an xsl style sheet. However it is displaying...
1
by: Yoshitha | last post by:
hi I have datalist control in my ASP.NET application the problem here is i have used a textbox with multiline true propertly when i enter data like "fdjsfhjksdhfjsdfhsdjhfsdfhsdjfhsd...
2
by: Carole MacDonald | last post by:
There have been lots of posts on this topic, but I haven't been able to apply any of the suggestions to my situation. I have an .aspx page with a form on it that has several submit buttons on...
5
by: Robert | last post by:
Hello Accessors I have some reports created in Access that are very good for what they do. However, it seems to me that when you are displaying information you don't need to print out that a...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
0
by: dipper | last post by:
I have a dataset with several tables. Now i want to create different dataviews displaying results from some of the tables. I manage to create a view displaying 1 table, but how do i create a view...
33
by: buss123 | last post by:
Hi all, combo box script code was working in IE perfectly with all modes but OnChange event was not working in FireFox(editable mode, if we select valuese that combo box values r...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.