please tell me array code for>>
store 10 characters in array and print in reverse order
4 replies to this topic
#1
Posted 17 May 2011 - 02:33 AM
|
|
|
#2
Posted 17 May 2011 - 10:33 AM
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.
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
Posted 17 May 2011 - 03:02 PM
#4
Posted 18 May 2011 - 02:52 AM
Do you know how to create an Array?
For example:
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 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
Posted 20 May 2011 - 07:01 AM
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


Sign In
Create Account

Back to top









