Jump to content

Array

- - - - -

  • Please log in to reply
4 replies to this topic

#1
tanaysaksena

tanaysaksena

    Newbie

  • Members
  • Pip
  • 8 posts
please tell me array code for>>
store 10 characters in array and print in reverse order

#2
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 403 posts
Well you should try out something yourself first.

Create the array and take input. Then loop through it from the last index to first. How to do each of these steps is pretty easily available in language syntax.

Please write it down and let us know where you are stuck.

#3
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
Let me google that for you
Let me google that for you

#4
DonCash

DonCash

    Newbie

  • Members
  • Pip
  • 7 posts
Do you know how to create an Array?

For example:


		char[] myArray = new char[10];

		

		myArray[0] = 'A';

		myArray[1] = 'B';

		myArray[2] = 'C';

		myArray[3] = 'D';

		myArray[4] = 'E';

		myArray[5] = 'F';

		myArray[6] = 'G';

		myArray[7] = 'H';

		myArray[8] = 'I';

		myArray[9] = 'J';


You now have an char Array holding 10 values.

To print them out you can use a for loop. Here is a simple for loop.
I'll leave you to work out how to print it in reverse..


		for(int i = 0; i < myArray.length; i++ ){

			System.out.println(myArray[i]);

		}



#5
tanaysaksena

tanaysaksena

    Newbie

  • Members
  • Pip
  • 8 posts
codes to store 10 characters in array and print in reverse order are
import java.io.*;

class Reverse

{

public static void main(String args[])

throws IOException

{

char a[] = newchar[10],i;

DataInputStream obj = new DataInputStream(System.in);

System.out.println("Enter 10 characters");

for(i=0;i<10;i++)

{

a[i]= (char)obj.read();

}

for(i=9;i>=0;i--)

{

System.out.print(a[i]);

}

}

}






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users