Reverse output of Java Classic algorithm

Source: Internet
Author: User

1 /**2 * Enter characters to reverse the array output3   */4 ImportJava.util.Scanner;5  Public classinRESERVE6 {7      Public Static voidMain (string[] args)8     {9 reverse ();Ten     } One      Public Static voidreverse () { A  -string[] arr =NewString[5]; -          for(inti=0;i<arr.length;i++){ theScanner input =NewScanner (system.in); -System.out.println ("Please enter" + (i+1) + "characters"); -Arr[i] =Input.next (); -         } +  -          for(intp=0,q=arr.length-1;p<q;p++,q--){ +String temp = "";//declaring temporary variables, storing arr[p] Atemp =Arr[p]; atARR[P] =Arr[q]; -ARR[Q] = temp;// -         } -ToString (arr);//Call the ToString () method output array -     } -  in      Public Static voidtoString (string[] arr) { -String str = "["; to          for(inti=0;i<arr.length;i++){ +str + =Arr[i]; -             if(i<arr.length-1){ thestr + = ","; *             } $         }Panax Notoginsengstr + = "]"; - System.out.println (str); the      } +}

Reverse output of Java Classic algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.