26 questions to answer written algorithm

Quote

Note: Some slight changes

Quote

To an integer into an array after reverse (required recursion)

package org.stack_queue;
public class Algorithm {

        //  Will a integer reverse in an array  ( Requires recursive implementation  )
        public void reverse(StringBuffer result, int num) {
                if (num != 0) {
                        result.append(num % 10);
                        reverse(result, num / 10);
                }
        }

        public static void main(String[] args) {
                StringBuffer result = new StringBuffer();
                new Algorithm().reverse(result, 1024);
                System.out.println(result);
        }

}

Quote

] Recursive palindrome judgments (such as: abcdedbca is palindromic, the interviewer to judge a simple understanding of the recursive procedure)

package org.stack_queue;
public class Algorithm {

        /**
         *  Recursive implementation Palindrome judgment  ( If  :abcdedbca It is a Palindrome, interviewer on recursive understand the simple program  )
         *
         * @param str
         *             To determine whether the string
         * @param begin
         *            0
         * @param end
         *             The length of a string
         * @return
         */
        public static boolean isPalindrome(char[] str, int begin, int end) {
                if (end <= 1)
                        return true;
                if (str[begin] == str[end]) {
                        return isPalindrome(str, begin + 1, end - 1);
                } else
                        return false;
        }

        public static void main(String[] args) {
                char[] str = new String("abcdedbca").toCharArray();
                System.out.println(Algorithm.isPalindrome(str, 0, str.length - 1));
                char[] str2 = new String("acbca").toCharArray();
                System.out.println(Algorithm.isPalindrome(str2, 0, str2.length - 1));
        }
}
分类:Java 时间:2010-06-20 人气:167
分享到:
blog comments powered by Disqus

相关文章

  • public static void main (String args []) parameters 2010-05-15

    String args [] is the main function of main parameters, namely array of strings. Using eclipse in the editing, right-click to run the Java files in the Run As option, select Run Configurations. Main class in the Project and complete the project, resp

  • Why public static void main (String args []){} 2010-11-06

    main () is a Java program entry, program execution is the beginning of this entry. Class is a class member, main () method must be public members. So that it can be called in the execution environment. main () method does not produce the object can b

  • 浅析C#中的Main(String[] args)参数输入问题 2014-07-20

    本篇文章主要是对C#中的Main(String[] args)参数输入问题进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助 指定相关的测试代码 首先,写一个用于测试的关于Main(String[] args)参数输入有关的代码类,如下: using System; public class Hello { public static void Main(String[] args) { switch (args[0]) { case "老板": Console.Write

  • How the eclipse of the main the String [] args parameter passed, and then export it 2010-12-26

    How the eclipse of the main the String [] args parameter passed, and then export it? In the Run menu to find Open Run dialog opens Select Java Application in the program need to run Select the Arguments Tab Enter the parameters in the Programe Argume

  • public void testStatementAddBatch () public void testConnCommit () 2011-09-01

    public void testStatementAddBatch() { Connection conn = null; Statement stmt = null; try { conn = getDBConnectionMsSqlBySuperAdmin(); stmt = conn.createStatement(); for(int i = 0; i < 100; i++) { String sql = " sql " + i; stmt.addBatch(sql);

  • String [] args = new String [] {sql.toString ()} 2011-06-29

    In this problem StringBuffer sql = new StringBuffer (); Which sql.toString results: 'Test User 1', 'male' String [] args = new String [] {sql.toString ()} args.length 1 results Obviously not what we need. Note: new String []{"","",&quo

  • Java String object, the classic problem of (new String ()) [switch] 2011-08-05

    Look at an example, the code is as follows: Java code public class Test { public static void main (String [] args) { String str = "abc"; String str1 = "abc"; String str2 = new String ("abc"); System.out.println (str == str1);

  • Remove the array from the specified character string and the formation of a new string array 2010-09-13

    Remove the array from the specified character string and the formation of a new string array, gcc compile. #include<stdio.h> #include<string.h> int main() { char ch1[]="askdaskaskdaskg",str[]=""; int i=0; while(ch1[i]!='\0'

  • String s = new String ("xyz") to create a number of String Object? 2010-06-20

    String s = new String ("xyz") to create a number of String Object? 2! "Xyz" as a constant string is first created, it is saved in the "string pool". The so-called string pool, simply, is to run from the beginning, you create

  • Bash string processing (and Java control) - 3 to (string) variable assignment 2011-09-07

    Bash string processing (and Java control) - 3 to (string) variable assignment In Java Simple assignment of s = "Hello"; Once assigned to the case of several variables s1 = s2 = "Same"; Assigned an integer (the integer converted to stri

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.299 (s). 12 q(s)