Reversing an int

Aright I'm not too sure how to go about this, but basically I want to take an integer from a user input (already got that figured out, so no worries) and reverse the numbers. basically the idea is that it's an id # and I need to flip it and then manipulate it. Any ideas on how to go about this? It works if i declare the input from the user as a String and such, but I figure that's just bad practice and I was wondering if there was a way to either get the whole int split into an array one number at a time or if there was a way to manipulate the Integer.
Or if there was a whole other way that I am not aware of. Thanks.
Just to make this clearer :
1)take # input from user
2)flip that number
3)manipulate it

I just wan to make sure you understand that reversing the 'numbers' in an int isn't really a mathematical concept. It's a string concept. Numbers don't have any inherent textual representation. For example the number five can be written as: V, 5, 1001, xxxxx, ect. We can make up new symbols for 5. So depending on what representation you use, your 'reversing' would have vastly different results. In other words, you are taking a String representation and reversing it. It's not really a numerical operation.

Similar Messages

  • Programming project - Reversed array

    I'm having a little trouble with this programming project. What I have to do:
    "Write a program named ReverseNumbers that prompts the user to enter 10 numbers, then writes the numbers in reverse order:
    Enter 10 numbers: 34 82 49 102 7 94 23 11 50 31
    In reverse order: 31 50 11 23 94 7 102 49 82 34
    Hint: Store the numbers in an array, starting at position 0. When printing the numbers, visit the elements of the array in reverse order."
    Here's what I have so far:
    import jpb.*;
    public class ReverseNumbers {
    public static void main(String[] args) {
    int[] reverse = new int [10];
    int num;
    int sum = 0;
    int sum2 = 0;
    int num1;
    for(num = 0; num < reverse.length; num++) {
    SimpleIO.prompt ("Enter ten numbers: ");
    String x=SimpleIO.readLine();
    reverse [num] = Integer.parseInt(x);
    for(num = 9; num >= 0; num--) {
    System.out.print( "  " + reverse [num]  );
    }

    warnerja wrote:
    Roridge wrote:
    Herko_ter_Horst wrote:
    Roridge wrote:
    You could delimit your input entry with a comma and then split on the input String to get your integers. e.g. "1,2,3,4,5,6,7,8,9,10"Right, because comma's are so much better than spaces...Yeah, well at least I Suggested something... you are so Elitist!I could have suggested that the OP bake a cake, but that would have helped about as much as you did.
    You are so Noobist!What is the deal with you two, are you like two lovers sitting next to each other determined to prove your Elite status?

  • Reverse number

    i'm using loops to reverse numbers and i have no clue on how to do it. i have to reverse the number using int. make the number 65000 into 00056

    hi,
    Probably you may also try this logic.
    private static int palindrome(int original) {
              int reverse=0;int counter=0;
              int cloneOriginal=original;
              do {
                   cloneOriginal=cloneOriginal/10;
                   counter++;    
                   }while(cloneOriginal >0);
              int temp[]=new int[counter];
              int increment=counter-1;
              do {
                   int lastDigit=original % 10;
                   original=original/10;
                   temp[increment]=lastDigit;
                   increment--;    
              }while(original >0);
              for(int i=0;i<temp.length;i++) {
                   int base=1;
                   for(int k=0;k<i;k++) {
                        base*=10;
                   int multiply=base * temp;
                   reverse+=multiply;
              return reverse;
    Thanks
    Prashant                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Making a program to detect a palindrome

    For my class I have to make a program that will detect whether or not a word is a palindrome. Here's what I have right now:
    import java.io.*;*
    *import java.util.*;
    public class Tester
            public static void main(String args[])
                     Scanner f = new Scanner(System.in);
                     System.out.print("Enter a word. ");
                     String word = f.nextLine();
                     char reverse=0, pali=0;                
                     int j, r;
                     for(j = word.length()-1; j>=0; j--)
                        reverse = word.charAt(j);      //To print the string backwards
                        for(r = 0; r <= word.length()-1; r++)
                            pali = word.charAt(r);     //Printing the string normally                     
                            if(pali!=reverse) 
                                System.out.println(word + " is not a palindrome.");
                                break;
                            else if(pali == reverse)
                            System.out.println(word + " is a palindrome.");                       
    }So basically what I'm trying to do there is to have one loop print each character backwards and a loop inside of that print each character forwards, and inside of the second loop I check to see whether the characters are identical, and if they are not, the word isn't a palindrome. It makes sense to me, but the output looks like this, using racecar as an example:
    Enter a word. racecar
    racecar is a palindrome.
    racecar is not a palindrome.
    racecar is not a palindrome.
    racecar is not a palindrome.
    racecar is not a palindrome.
    racecar is not a palindrome.
    racecar is not a palindrome.
    racecar is a palindrome.
    racecar is not a palindrome.I understand why it prints that many times, because it's still iterating inside the first loop, but I have no idea how break the first loop. Also, clearly, it just doesn't work... any tips?
    All help is greatly appreciated.

    Thanks for the reply.
    I'm not sure if I got exactly what you meant, but here's how I understood it:
    import java.io.*;
    import java.util.*;
    public class Palindrome
            public static void main(String args[])
                     Scanner f = new Scanner(System.in);
                     System.out.print("Enter a word. ");
                     String word = f.nextLine();
                     boolean b = true;
                     char pali = 0, reverse = 0;
                     int j, r;
                     j = word.length()-1;
                     r = 0;
                     while(j!=r)
                            pali = word.charAt(r);
                            reverse = word.charAt(j);
                            if(pali!=reverse)
                                        b = false;
                                        break;
                            else
                                    b = true;
                                    r++;
                                    j--;
                 if(b)
                 System.out.println(word + " is a palindrome.");
                 else
                 System.out.println(word + " is not a palindrome.");
        }I made a mistake somewhere, because when I input a palindrome it might say that it is a palindrome(more than once for some reason), but if I input a non-palindrome it doesn't respond at all. No idea why, because I have an "else" statement that should make it do so...
    So where did I go wrong?

  • Do you use Virtual Box VM... Please help with this.

    hey everyone I'm extremely new with all this stuff...
    I have a iMac 10.5.4 with the most current version of Virtual Box.
    When i load Virtual Box everything is rocking and extremely cool... but after an hour or so my network/server connections dies off on the mac side.
    when i go to GO >> Connect to Server >>
    smb://ipaddress
    I get this pop up...
    error connecting to the server >>
    I click OK and i get an error code -36
    the only way for me to connect again to the server is to shut down everything and restart the iMac it works just fine and i load VB back up and than everything works for about another hour or so and than i have to restart everything again.
    any clues to my issue?
    thanks for helping a newbie!
    cp

    ...but since you are learning, and would like to know where was the bug, I tried your code and updated it.
    The only two small problems I found:
    1. You have a while loop that checks if there are more tokens.. it's not needed and this while loop will only run because by the second run, you would have consumed all the tokens in the for loop, check would fail and while loop will be exited. [I have removed this while loop in my version below]
    2. Now, here is the bug:your for loop has a condition that evaluates (i < st.countTokens()).
    Now count tokens will only return "remaining" tokens. Assuming test string "this is a test", countTokens return 4. Then as you consume the first token, it is 3, then 2 then 1. All this while for loop's i is going 1,2...
    i = 0, countTokens = 4
    i = 1, countTokens = 3
    i = 2, countTokens = 2, check fails, and for loop is exited.
    So all you have in your array is first two tokens. Rest of the array is null as it was when you created the array.
    So then when you loop back and check index 3,2,1,0.. 3 and 2 elements are still nill, that's why you get the result you are getting.
    Here is the fixed code:
    String sentence = "this is second test"; //String variable to hold user input
    String output = ""; //String variable to enable display of output
    String buffer = "";//String variable to hold output
    st = new StringTokenizer(sentence);
    int tokenCount = st.countTokens();
    //Array to hold tokens
    String tokenHolder[] = new String[tokenCount];
    //Walk through the tokens
    for (int i = 0; i < tokenCount; i++)
         tokenHolder[i] = st.nextToken();
    String reversedTokens[] = new String[tokenCount];
    //Walk through the array in reverse
    for (int j = tokenCount-1; j >= 0; j--)
    //Add the reversed token to the ouptut string
    output += tokenHolder[j] + " ";
    System.out.println(output);
    }

  • Character Input

    Hello Everyone
    If someone is able to assist me that would be great, my problem is that i am trying to get my code to produce the reverse string only if the letter 'B' is input but i have been fiddling around and cant get it to compile for me. Is there anyone that can assist me please. Thanks in Advance
    System.out.println("Enter a selection from the menu above:");
    String line = scannerObject.nextLine();
    char input = 'B'
    if (input = 'B');
    Scanner in = new Scanner(System.in);
    String prompt = "Enter a string to reverse";
           System.out.println(prompt);
           String input = in.nextLine();
           String reverse = "";
           for(int i = input.length()-1; i >= 0; i--)
            reverse += input.charAt(i);
           System.out.println("Reverse string  : " + reverse);
    }

    your code is a bit messed up
    import java.util.Scanner;
    public class FirstProgram {
         public static void main(String[] args) {
              Scanner scannerObject = new Scanner(System.in);
              System.out.println("assignment one menu.");
              System.out.println("A.PRINT A NUMBER PATTERN.");
              System.out.println("REVERSE A STRING.");
              System.out.println("EXIT THE PROGRAM.");
              System.out.println("Enter a selection from the menu above:");
              String line = scannerObject.nextLine();
              char input = 'B';
              if (input == 'B') {
                   Scanner in = new Scanner(System.in);
                   String prompt = "Enter a string to reverse";
                   System.out.println(prompt);
                   String inputStr = in.nextLine();
                   String reverse = "";
                   for (int i = inputStr.length() - 1; i >= 0; i--) {
                        reverse += inputStr.charAt(i);
                   System.out.println("Reverse string : " + reverse);
    }

  • This class definition kind of looks like a mess.

    It seems I had the right idea and especially after I got some help for my class
    "Complex." The last part of the class won't compile though. I'm using NetBeans.
    The question I need to answer is "Write the toString method such that it
    displays an object in the following format: 5 - 3j where 5 and -3 are the
    contents of the instance variables. Here is the code I have so far:
    {code}
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package tutorial8;
    * @author Aleks
    public class Complex {
    public static void main(String[] args) {
    private int I; // Real Part
    private int J; // Imaginary Part
    private int a;
    private int b;
    private int c=5;
    private int d=-3;
    public int reverse;
    public int moveBy;
    public void setComplex(int I, int J, int a, int b)
    this.I=a;
    this.J=b;
    public int getI()
    return I;
    public int getJ()
    return J;
    public int getc()
    return c;
    public void setComplex(int I, int J)
    this.I=I;
    this.J=J;
    if (I==J)
    System.out.println("true");
    else
    System.out.println("false");
    public void setreverse(int a, int b)
    this.I=b;
    this.J=a;
    public int getreverse()
    return reverse;
    public void setmoveBy(int I, int J, int c)
    this.I=I+c;
    this.J=J+c;
    public int getmoveBy()
    return moveBy;
    System.out.println(c+d*J.toString());
    {code}

    theconfused3 wrote:
    I was playing around with your suggestions and all the code
    I tried didn't work. So I will give a sample piece of code which
    may not be the best approximation of what is required out of
    all my attempts.
    public String Remove toString();
    return c+d*J;
    }I've never heard of "Remove".Why did you put "Remove" in there? Do you normally add words you've never heard of, and which the compiler rejects, randomly into your code, hoping it will magically do the right thing, even though if you just read it as plain English text it makes no sense? Think about what you're doing! Each step you take should have a specific purpose, a specific meaning, and have a specific result!
    Also your implementation still isn't going to work. The assignment gave a specific format for the resulting string, and you're not following it. (Hint: toString produces a textual representation of the object.)

  • Palindrome

    I need a program fitting these rules:
    -This program must be named Palindrome.
    -Function adjust - This function will be passed the original string from main. This function will be passed the original string from main. This function will traverse the string in order and pull each character. If this character is a letter, it will add this letter to the new string. If it is not a letter, the character will be ignored and will move on to the next letter. The adjusted string will be passed back to main. (Basically removing all blank spaces and all punctuation marks from the original string.)
    -Function reverse - This function will be passed the adjusted string from main. First, it makes sure that all the characters of the string are in lowercase. Second, it traverses the string and pulls each character in reverse order. It will add the letter to a new string. This string will be returned to main. (Remember that this reverses the string that does not have any spaces or punctuation marks.)
    -Function match - This function will be passed the adjusted string and the reversed string. It will perform the task of checking to see if the strings are the same. The function will return either true or false to the main.
    -Main - This will test our program and check both a palindrome string and a non-palindrome string. Be sure that you include enough variables for all items that are to be used and to hold all answers that are returned from other functions.
    ( This program will only have input in the code not in the cmd prompt, the sentence that should work is Madam, I'm Adam!, the one that should work is This should fail!, make sure it prints if it is a palindrome or not. Any help would be greatly appreciated please try to keep it lower level so i can understand it,)

    As specified, this program will never work.
    The spec for the reverse function says: "First, it makes sure that all the characters of the string are in lowercase". Which, quite apart from being bad design (nothing in the method name tells us the string is going to be down shifted) leaves a potentialy mixed case string being compared with a lower case one.
    To fix this, downshift in the adjust method (not quite such bad design as the name is so vague that you can justifiably do whatever you like in it).
    Enjoy!
    public class Astrads1
         static String adjust(String source)
              String adjusted= "";
              for (int i= 0; i< source.length(); i++) {
                   if (Character.isLetter(source.charAt(i)))
                        adjusted += source.charAt(i);
              return adjusted.toLowerCase();
         static String reverse(String source)
              String reversed= "";
              for (int i= source.length()-1; i >= 0; i--)
                   reversed += source.charAt(i);
              return reversed;
         static boolean match(String adjusted, String reversed)
              for (int i= 0; i< adjusted.length(); i++) {
                   if (adjusted.charAt(i) != reversed.charAt(i))
                        return false;
              return true;
         public static void main(String[] argv)
              String[] sources= new String[] {
                   "Madam, I'm Adam!", "This should fail!" };
              for (int i= 0; i< sources.length; i++) {
                   String source= sources;
                   String adjusted= adjust(source);
                   String reversed= reverse(adjusted);
                   boolean matches= match(adjusted, reversed);
                   System.err.println(
                        "Source= " source
                        "\nAdjusted= " adjusted
                        "\nReversed= " reversed
                        "\nMatches= " +matches);
                   System.out.println(
                        "'" source "' is" +(matches ? "" : " not") +" a palindome");

  • Please help with this....(thank you)

    Hi. I am new to the Dev. Connection and new to Java Programming. In fact what I am posting is a homework assignment that I have put several hours into and I cannot get it to perform properly. I am not looking for someone to do it for me --- rather to give me some pointers on how I can find the error and fix the problem myself. I mean what good would it do me if you (the experienced programmer) solved the whole thing for me? I want to be a kick-ass programmer and I would never be any good if everyone else did my work.
    Thanks in advance for any advice.
    Program Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class ReverseString
         Method Name: Main()
         Return Value: none
         Input Parameters: none
         Method Description: This is the method that makes it all go!
         public static void main( String args[] )
              String sentence = ""; //String variable to hold user input
              String output = ""; //String variable to enable display of output
              String buffer = "";//String variable to hold output
              //Display an input dialog
              sentence = JOptionPane.showInputDialog(
    "Enter the Sentence you want to see in REVERSE:");
              //Pass String variable 'sentence' to StringTokenizer object
              StringTokenizer st = new StringTokenizer(sentence);
                   //Array to hold tokens
                   String tokenHolder[] = new String[st.countTokens()];
                   //Walk through the tokens
                   while (st.hasMoreTokens())
                        for (int i = 0; i < st.countTokens(); i++)
                             tokenHolder[i] = st.nextToken();
                   String reversedTokens[] = new String[tokenHolder.length];
                   //Walk through the array in reverse
                   for (int j = tokenHolder.length - 1; j >= 0; j--)
                        //Add the reversed token to the ouptut string
                        output += tokenHolder[j] + " ";
              //Display Output
              JOptionPane.showMessageDialog (null, output,
              "Reversing the Contents of an Input String.",
              JOptionPane.INFORMATION_MESSAGE );
         //Exit cleanly
         System.exit( 0 );
         }//EOMain
    }//EOF
    The problem is that when I run this application the output does not yield a string that has had the tokens extracted from the user input in reverse. Instead for the input "this is a test" --I get "nullnull is test". Why?
    Thanks again.

    ...but since you are learning, and would like to know where was the bug, I tried your code and updated it.
    The only two small problems I found:
    1. You have a while loop that checks if there are more tokens.. it's not needed and this while loop will only run because by the second run, you would have consumed all the tokens in the for loop, check would fail and while loop will be exited. [I have removed this while loop in my version below]
    2. Now, here is the bug:your for loop has a condition that evaluates (i < st.countTokens()).
    Now count tokens will only return "remaining" tokens. Assuming test string "this is a test", countTokens return 4. Then as you consume the first token, it is 3, then 2 then 1. All this while for loop's i is going 1,2...
    i = 0, countTokens = 4
    i = 1, countTokens = 3
    i = 2, countTokens = 2, check fails, and for loop is exited.
    So all you have in your array is first two tokens. Rest of the array is null as it was when you created the array.
    So then when you loop back and check index 3,2,1,0.. 3 and 2 elements are still nill, that's why you get the result you are getting.
    Here is the fixed code:
    String sentence = "this is second test"; //String variable to hold user input
    String output = ""; //String variable to enable display of output
    String buffer = "";//String variable to hold output
    st = new StringTokenizer(sentence);
    int tokenCount = st.countTokens();
    //Array to hold tokens
    String tokenHolder[] = new String[tokenCount];
    //Walk through the tokens
    for (int i = 0; i < tokenCount; i++)
         tokenHolder[i] = st.nextToken();
    String reversedTokens[] = new String[tokenCount];
    //Walk through the array in reverse
    for (int j = tokenCount-1; j >= 0; j--)
    //Add the reversed token to the ouptut string
    output += tokenHolder[j] + " ";
    System.out.println(output);
    }

  • Problems with a while loop within a method... (please help so I can sleep)

    Crud, I keep getting the wrong outputs for the reverseArray. I keep getting "9 7 5 7 9" instead of "9 7 5 3 1". Can you guys figure it out? T.I.A (been trying to figure this prog out for quite some time now)
    * AWT Sample application
    * @author Weili Guan
    * @version 1999999999.2541a 04/02/26
    public class ArrayMethods{
       private static int counter, counter2, ndx, checker, sum, a, size, zero;
       private static int length;
       private static int [] output2, output3, reverse, array;
       private static double output;
       private static double dblsum, dblchecker, average;
       public static void main(String[] args) {
          //int
          //int [] reverse;
          System.out.println("Testing with array with the values [1,3,5,7,9]");
          size = 5;
          array = new int [size];
          reverse = new int [size];
          array[0] = 1;
          array[1] = 3;
          array[2] = 5;
          array[3] = 7;
          array[4] = 9;
          System.out.println("Testing with sumArray...");
          output = sumArray(array);
          System.out.println("Sum of the array: " + sum);
          System.out.println();
          System.out.println("Testing with countArray...");
          output = countArray(array);
          System.out.println("Sum of the elements : " + checker);
          System.out.println();
          System.out.println("Testing with averageArray...");
          output = averageArray(array);
          System.out.println("The average of the array : " + average);
          System.out.println();
          System.out.println("Testing with reverseArray...");
          output2 = reverseArray(array);
          output3 = reverseArray(reverse);
          //System.out.print(reverse[4]);
          System.out.print("The reverse of the array : ");
          for(ndx = 0; ndx < array.length; ndx++){
             System.out.print(reverse[ndx] + " ");
       private ArrayMethods(){
       public static int sumArray(int[] array){
          checker = 0;
          ndx = 0;
          counter = 0;
          sum = 0;
          while(counter < array.length){
             if (array[ndx] > 0){
                checker++;
             counter++;
          if(array.length > 0 && checker == array.length){
             while(ndx < array.length){
                sum += array[ndx];
                ndx++;
             return sum;
          else{
             sum = 0;
             return sum;
        /*Computes the sum of the elements of an int array. A null input, or a
        zero-length array are summed to zero.
        Parameters:
            array - an array of ints to be summed.
        Returns:
            The sum of the elements.*/
       public static int countArray(int[] array){
          checker = 0;
          ndx = 0;
          counter = 0;
          sum = 0;
          while(counter < array.length){
             if(array[ndx] > 0 && array[ndx] != 0){
                checker++;
             counter++;
          return checker;
        /*Computes the count of elements in an int array. The count of a
        null reference is taken to be zero.
        Parameters:
            array - an array of ints to be counted.
        Returns:
            The count of the elements.*/
       public static double averageArray(int[] array){
          dblchecker = 0;
          ndx = 0;
          counter = 0;
          dblsum = 0;
          while(counter < array.length){
             if(array[ndx] > 0){
                dblchecker++;
             counter++;
          if(array.length > 0 && checker == array.length){
             while(ndx < array.length){
                dblsum += array[ndx];
                ndx++;
             average = dblsum / dblchecker;
             return (int) average;
          else{
             average = 0;
             return average;
        /*Computes the average of the elements of an int array. A null input,
        or a zero-length array are averaged to zero.
        Parameters:
            array - an array of ints to be averaged.
        Returns:
            The average of the elements.*/
       public static int[] reverseArray(int[] array){
          ndx = 0;
          counter = 0;
          counter2 = 0;
          if(array.length == 0){
             array[0] = 0;
             return array;
          else{
                //reverse = array;
             while(ndx <= size - 1){
                   reverse[ndx] = array[4 - counter];
                   counter++;
                   ndx++;
                   System.out.print("H ");
          return reverse;
        /*Returns a new array with the same elements as the input array, but
        in reversed order. In the event the input is a null reference, a
        null reference is returned. In the event the input is a zero-length array,
        the same reference is returned, rather than a new one.
        Parameters:
            array - an array of ints to be reversed.
        Returns:
            A reference to the new array.*/
    }

    What was the original question? I thought it was
    getting the desired output, " 9 7 5 3 1."
    He didn't ask for improving the while loop or the
    reverseArray method, did he?
    By removing "output3 = reverseArray(reverse):," you
    get the desired output.Okay, cranky-pants. Your solution provides the OP with the desired output. However, it only addresses the symptom rather than the underlying problem. If you'd bother yourself to look at the overall design, you might see that hard-coding magic numbers and returning static arrays as the result of reversing an array passed as an argument probably isn't such a great idea. That's why I attempted to help by providing a complete, working example of a method that "reverses" an int[].
    Removing everything and providing "System.out.println("9 7 5 3 1");" gets him the desired output as well, but (like your solution) does nothing to address the logic problems inherent in the method itself and the class as a whole.

  • Operation Green Blood

    this is in extension of thread
    http://forum.java.sun.com/thread.jsp?forum=31&thread=303696
    thanks for flag -Xmx128
    but here is the code
    PLEASE HELP IN MAKING THIS "A everytime working code.."
    OPERAION GREEN BLOOD
    This source is made by ballubadshah
    the code changes supported audio  file into reverse direction
    well the code is complete but not stable.
    The comment in between the code gives the details for the mission
    see description and mission below
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    import javax.sound.sampled.*;
    public class backmasking
      public static void main(String args[])
        if (args.length == 0)
          System.out.println("Usage : java backmasing audiofilename  ");
          System.out.println("---------------------------------------");
          System.out.println(" please provide satan a audio file     ");
          System.exit(0);
          System.out.println("-------Welcome to the world of Satan------");
        final int bufSize = 16384;// some buffer
        File file1 = new File(args[0]);// here is the input wavfile
        AudioInputStream ais1 = null;// a ais init
        try
        ais1 = AudioSystem.getAudioInputStream(file1);
        }catch (UnsupportedAudioFileException e)
        {    System.out.println("File Format not supported. \nTOO BAD");  System.exit(0); }
        catch  (IOException ee)
        {    System.out.println("File "+file1.getName()+ " not found.\nTOO BAD");System.exit(0);}
        AudioFileFormat.Type aff = null;
        try
        aff= AudioSystem.getAudioFileFormat(file1).getType();
        catch(UnsupportedAudioFileException uafe)
        { System.out.println("Some error has occured in file format\nTOO BAD");System.exit(0);}
        catch(IOException uafe)
        { System.out.println("Input / output error");System.exit(0);}
        // file format
        System.out.println("Satan is processing your file ...");
        System.out.println("Satan says ...");
        System.out.println("Audio file type = "+ aff);
        System.out.println("AudioInputStream = "+ais1+" GOOD");
        AudioFormat af1 = ais1.getFormat();      // this af is used  later too
        System.out.println("AudioFormat = "+af1+" GOOD");
        int frameSizeInBytes = af1.getFrameSize();
        System.out.println("FrameSize in Bytes = "+frameSizeInBytes);
        long leng = file1.length();// leng is file length
        System.out.println("FileLength = "+leng);
        AudioFileFormat.Type aff[] = AudioSystem.getAudioFileTypes(ais1);// file format
        for (int i = (aff.length-1) ;i >= 0 ; i--)
          System.out.println(aff);
    //reversing process
    int stop = (int)leng-1;
    // System.out.println("I am Here");
    long framelength = ais1.getFrameLength();
    System.out.println("Frame length = "+framelength);
    ---description...
    before this comment the data from a wav file is taken.
    after this...
    bytes are fetched from audioinputstream ais1 of that file
    these bytes are rb[].
    then these bytes rb are send to a file some temp file...
    this is done bcos of lack of memory available...
    then later after part ONE
    these rb again taken from tempfile are send to audioutputstream
    for getting a reverse of actual wav file...
    --- mission
    i want to have reverse of audio wav file
    with support for large size files
    cos my one does not support large file size
    nor i think it is the best...
    i want it to be working for every file
    so edit this code and send
    else give a appropriate hint...
    byte rb[] = null ;
    // try
    rb = new byte[stop];
    // catch (IOException ee)
    // {System.out.println("The file size is too big./nTOO BAD");System.exit(0);}
    //i dont want to get the above error ee in code for any file size
    //means if stop is bigger than RAM then outofmemmoryerror will occur
    //this is very cheap but ...
    //try giveing any other alternative too...
    System.out.println("Reading file "+file1.getName());
    try
    stop=ais1.read(rb);// all file bytes are read here into rb
    }catch (IOException ioe){System.out.println("some good error");}
    System.out.println("Byte rb length = "+rb.length);
    System.out.print("Phase 5 complete / ");
    System.out.println("Entering phase 6");
    System.out.println("Stop = "+stop);
    File file2 = new File("rv"+file1.getName()+".pramod");
    System.out.println("Reading Complete...");
    FileOutputStream fos2 = null;
    try
    fos2= new FileOutputStream(file2);
    System.out.println("Writing reverse temp data to file "+file2.getName()+" takes time");
    for(int l = 0 ;l < stop ;l++ )
    fos2.write(rb[stop-l]);
    }catch (FileNotFoundException e){System.out.println("File not found...");}
    catch(IOException eeeee) {
    System.out.println("File cannot be written some problem."); }
    rb = null;
    System.out.println("--------End of part ONE----------");
    System.out.println(" Entering phase 666 ");
    FileInputStream fis= null;
    try
    fis = new FileInputStream(file2);
    }catch(FileNotFoundException ee){}
    File filu= new File("rv"+file1.getName());
    rb = new byte[stop];
    try
    // for(int l = 0 ;l < stop ;l++ )
    fis.read(rb,0,rb.length);
    }catch (FileNotFoundException e){System.out.println("File not found...2 time");}
    catch(IOException eeeee) {
    System.out.println("File cannot be written some problem. 2 time"); }
    ByteArrayInputStream bais = new ByteArrayInputStream(rb);
    // int frameSizeInBytes = af1.getFrameSize();
    AudioInputStream audioInputStream = new AudioInputStream(bais, af1, rb.length / frameSizeInBytes);
    try
    AudioSystem.write(audioInputStream,aff, filu);
    System.out.println("NEW REVERSE "+ aff +" FILE -- "+filu.getName()+" -- CREATED.");
    System.out.println("BYE BYE from satan");
    System.out.println("Well backmasking is famous because of satan.");
    System.out.print("OPERATION GREEN BLOOD COMPLETE...");
    catch(IOException eeeee)
    System.out.println("File cannot be written some problem.");
    System.exit(0);

    And what about the other formats like au, aifc, aiff and snd?
    The Java Sound API can handle these formats, so we should write methods that can handle that formats, too. Otherwise it won't be really platform-independent.
    All formats are supported, because neither the order of the bytes is changed, nor the order of the samples. Only frames are reversed.
    Okay, here is some code (Sometimes I think I'm stupid. I made a big mistake: processing the data in several chunks is really hard (or impossible) to implement, because the data from the end is needed at the same like the data at the begin. I'm sorry for that.)
    import javax.sound.sampled.*;
    import java.io.*;
    public class ReverseFrames {
    public static void main(String[] args){
      reverse(new File("c:/windows/media/chimes.wav"), new File("c:/temp/reversed.wav"));
    public static void reverse(File myFile, File reversedFile){
       try{
       AudioInputStream ais = AudioSystem.getAudioInputStream(myFile);
       byte[] buffer = new byte[(int)reversedFile.length()];
       int read, totalRead = 0, framesize = ais.getFormat().getFrameSize();
       while((read = ais.read(buffer)) != -1){
        reverseBytes(buffer, read, framesize);
         totalRead += read;
       ais.close();
       ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
       AudioInputStream audioOut = new AudioInputStream(bais, ais.getFormat(), totalRead/ais.getFormat().getFrameSize());
       AudioSystem.write(audioOut, AudioFileFormat.Type.WAVE, reversedFile);
      }catch(Exception e){
       e.printStackTrace();
    public static void reverseBytes(byte[] array, int len, int framesize){
      byte temp;
      for(int i=0; i<len/2; i+=framesize){
       for(int j=0; j<framesize; j++){
        temp = array[i+j];
        array[i+j] = array[len-i-framesize+j];
        array[len-i-framesize+j] = temp;
    }I tried it, it worked well. (I'm still angry with me about that thing with processing data in chunks. }:-( )

  • No hair

    I've been working on this code for a couple of days now and no longer have any hair. I want to evaluate a number to see if it is the same forward and backward. If not, the forward and backward numbers need to be added together and the sum needs to be evaluated. This process continues until a Palindromic number is reached.
    I have several problems:
    1) When I add the original and reverse numbers together , some how the original number is always zero.
    2) I can't figure out the correct syntax for comparing the two numbers. I've tried compareTo (using Integers) and if int1=int2 then ...
    3) Once the two numbers are compared, and I have the sum, I need to re-evaluate the sum.
    I would like to get my code to work. I'm sure there is a more streamlined process, but I will try to streamline it after I learn more.
    Thanks in advance.
    import java.io.*;
    import java.awt.*;
       public class reverse1  {
          public static void main(String [] args) throws IOException {
         BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
         int OriginalNum;  //the number that will be input by the user
         int numTry = 0;  //numbers of tries
         boolean foundIt = false;
         //read the input from the user
         System.out.print("Please enter a number: ");
         OriginalNum = Integer.parseInt(keyboard.readLine());
    //checking if it is a single digit
         if (OriginalNum != 1) {
            foundIt = true;
    //evaluate number to see if it is a palindrome
         //reverse number
         int ReverseNum = 0;
              while (OriginalNum != 0) {
              ReverseNum = ReverseNum*10 + OriginalNum%10;
              OriginalNum = OriginalNum/10;
         System.out.println("The original number is " +  OriginalNum + ".");
         System.out.println("The reverse number is " +  ReverseNum + ".");
         Integer Rnum = new Integer(ReverseNum);
         Integer Onum = new Integer(OriginalNum);
         if (OriginalNum == ReverseNum) {
            foundIt = true;
         //add the original and reverse numbers together
         int NSum = OriginalNum + ReverseNum;
         //output the answer
         System.out.println("The sum is " + NSum + ".");
         //evaluate if it is a palindrome
         //number of Tries
         numTry++;
         System.out.println("Tried " + numTry + " times.");
         if (foundIt) {
         System.out.println("It IS a palindrome!");
          }//end main
       }//end class

    public class ReverseNum {
        public static void main(String[] args) {
            int original  = 125;      // Input.
            while(true) {
                int copy      = original;
                int reverse   = 0;
                while(copy != 0) {
                    reverse  = reverse *10 +(copy %10);
                    copy     = copy /10;
                if(original == reverse) {
                    System.out.println("Palindrome!!!");
                    break;
                } else {
                    // Compute the sum and start again.
                    original +=  reverse;
            System.out.println("Number = " +original);
    }

  • About Collections class

    The Collections Framework defines several algorithms that can be applied to collections
    and maps.These algorithms are defined as static methods within the Collections class.
    These algorithms support List,Map,Set,Enumeration,SortedMap,SortedSet.But not
    Iterator.
    Is it fixed by Java that no Iterator can use within any of those algorithms of Collections
    class?
    Or, Is it only Maps class support Iterator for it's algorithms?

    Thanks everybody for replies.
    import java.util.*;
    public class AlgorithmsDemo {
         public static void main(String[] args) {
              LinkedList<Integer> ll=new LinkedList<Integer>();
              System.out.println("Size of LinkedList ll: "+ll.size());
              System.out.println("Contents of LinkedList ll: "+ll);
              ll.add(-8);
              ll.add(20);
              ll.add(-20);
              ll.add(8);
              System.out.println("Now the size of linkedList ll: "+ll.size());
              System.out.println("Now the contents of linkedlist ll: "+ll);
              Comparator<Integer> comp=Collections.reverseOrder();
              Collections.sort(ll,comp);
              System.out.print("List sorted in reverse: ");
              for(int i:ll)
                   System.out.print(i+" ");
              System.out.println();
              Collections.shuffle(ll);
              System.out.print("List shuffled: ");
              for(int i:ll)
                   System.out.print(i+" ");
              System.out.println();
              System.out.println("Minimum: "+Collections.min(ll));
              System.out.println("Maximum: "+Collections.max(ll));
    }If I want to use Iterator instead of Comparator then what changes need to do
    within above code?

  • TDS is not getting reversed in T.Code:  F-54 -Clear Vendor down payment

    Hi,
    Please help on the below issue:-
    1. We passed one entry relating to down payment for fixed asset.  We deducted TDS also (50% down payment).
    2. We passed MIRO also.  There we deducted TDS on full value of invoice amount.
    3. While making T.Code:  F-54-clear vendor down payment, TDS is not getting reversed.
    Thanks in Advance.
    Regards
    Srinivas

    Hi,
    Please check  whether the Challan has been done for both downpayment & invoice before downpayment clearing was done.may be That is why the system doesn't consider reversal of wht at the time of downpayment clearing as tax has already been remitted.Please refer with_item table. The int challan number & dateare for the downpaynment & for the invoice.
    Hope this helps.
    Regards
    Ravinagh Boni

  • Integer array reverse

          * arrayReverse method
          * intArray = {1,2,3,4,5,6,7,8,9,10}, this method is supposed to
          * reverse the values (e.g. 10,9,8,7,6,5,4,3,2,1..)
          public void arrayReverse()
                    for (int index = 0; index < 4; index++)
                         for (int scan = 9; index > 5; scan--)
                             int temp = intArray[index];
                             arrayChange(index, intArray[scan]);
                             arrayChange(scan, intArray[temp]);
           }I've been attempting this for the better part of my evening and can't seem to make out what I'm doing wrong.
    I know for instance, that my for loops are at fault; but I haven't made one step forward in switching any of the values.
    any help would be greatly appreciated
    v/r,
    mess

    Suggestions:
    Instead of
    int next = 9;Do
    int next = intArray.length;And instead of
    for (int index = 0; index < 4; index++)do
    for (int index = 0; index < intArray.length/2; index++)This will make your code work no matter if intArray has 10 elements, 3 elements or 25 elements. And it's what I meant when I said to get rid of the magic numbers.

Maybe you are looking for

  • Outstanding balance

    Ok so in about January or Feburary, I had a gift card which i used to get some music. I went over balance and now im worried that the balance would have increased. does anyone know if thats the case?

  • Add new Oracle VM 3.0.2 server & network, SAN configuration

    Hi, I'm installing an Oracle VM 3.0.2 cluster with 4 Oracle VM servers. The cluster has been installed with 2 servers, the network has been configured (3 VM Network and 1 admin network). The storage has been configured, some VM has been created. And

  • Mountain Lion : Problem with Graphic on Macbook 13"

    I recently updated to Mountain Lion, and it seems like the graphics are glitching big-time, to the point where the computer becomes unusable and i have to restart... I tried a 'clean' install (formatting and usb-install) but the but the problem persi

  • I want to change my ipad2 into an ipad3.....

    I bought an ipad2 at best buy last 03/03/12 in a promo price of 404.99 then i found out that price has been lowered then they refunded me of 47.81 on 03/17/12.. Could i change this ipad 2 into ipad3? And how much money should i add?

  • Time machine for iPhoto restore keeps searching - never comes back

    I need to restore to a previous time machine backup but when I go into iPhoto to try to look at the backups, it keeps saying searching for photos (I can use the date bar on the right but it never loads - waited 10 hours and still no load). I do have