Java tutorial
//package com.java2s; /* * Copyright 2011-2013 HTTL Team. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { public static byte[] createSequence(byte begin, byte end) { int sign = end > begin ? 1 : -1; int len = Math.abs(end - begin) + 1; byte[] seq = new byte[len]; for (int i = 0; i < len; i++) { seq[i] = (byte) (begin + i * sign); } return seq; } public static char[] createSequence(char begin, char end) { int sign = end > begin ? 1 : -1; int len = Math.abs(end - begin) + 1; char[] seq = new char[len]; for (int i = 0; i < len; i++) { seq[i] = (char) (begin + i * sign); } return seq; } public static short[] createSequence(short begin, short end) { int sign = end > begin ? 1 : -1; int len = Math.abs(end - begin) + 1; short[] seq = new short[len]; for (int i = 0; i < len; i++) { seq[i] = (short) (begin + i * sign); } return seq; } public static int[] createSequence(int begin, int end) { int sign = end > begin ? 1 : -1; int len = Math.abs(end - begin) + 1; int[] seq = new int[len]; for (int i = 0; i < len; i++) { seq[i] = begin + i * sign; } return seq; } public static long[] createSequence(long begin, long end) { int sign = end > begin ? 1 : -1; int len = (int) (Math.abs(end - begin) + 1); long[] seq = new long[len]; for (int i = 0; i < len; i++) { seq[i] = begin + i * sign; } return seq; } public static float[] createSequence(float begin, float end) { int sign = end > begin ? 1 : -1; int len = (int) (Math.abs(end - begin) + 1); float[] seq = new float[len]; for (int i = 0; i < len; i++) { seq[i] = begin + i * sign; } return seq; } public static double[] createSequence(double begin, double end) { int sign = end > begin ? 1 : -1; int len = (int) (Math.abs(end - begin) + 1); double[] seq = new double[len]; for (int i = 0; i < len; i++) { seq[i] = begin + i * sign; } return seq; } public static Byte[] createSequence(Byte begin, Byte end) { int sign = end > begin ? 1 : -1; int len = Math.abs(end - begin) + 1; Byte[] seq = new Byte[len]; for (int i = 0; i < len; i++) { seq[i] = (byte) (begin + i * sign); } return seq; } public static Character[] createSequence(Character begin, Character end) { int sign = end > begin ? 1 : -1; int len = Math.abs(end - begin) + 1; Character[] seq = new Character[len]; for (int i = 0; i < len; i++) { seq[i] = (char) (begin + i * sign); } return seq; } public static Short[] createSequence(Short begin, Short end) { int sign = end > begin ? 1 : -1; int len = Math.abs(end - begin) + 1; Short[] seq = new Short[len]; for (int i = 0; i < len; i++) { seq[i] = (short) (begin + i * sign); } return seq; } public static Integer[] createSequence(Integer begin, Integer end) { int sign = end > begin ? 1 : -1; int len = Math.abs(end - begin) + 1; Integer[] seq = new Integer[len]; for (int i = 0; i < len; i++) { seq[i] = begin + i * sign; } return seq; } public static Long[] createSequence(Long begin, Long end) { int sign = end > begin ? 1 : -1; int len = (int) (Math.abs(end - begin) + 1); Long[] seq = new Long[len]; for (int i = 0; i < len; i++) { seq[i] = begin + i * sign; } return seq; } public static Float[] createSequence(Float begin, Float end) { int sign = end > begin ? 1 : -1; int len = (int) (Math.abs(end - begin) + 1); Float[] seq = new Float[len]; for (int i = 0; i < len; i++) { seq[i] = begin + i * sign; } return seq; } public static Double[] createSequence(Double begin, Double end) { int sign = end > begin ? 1 : -1; int len = (int) (Math.abs(end - begin) + 1); Double[] seq = new Double[len]; for (int i = 0; i < len; i++) { seq[i] = begin + i * sign; } return seq; } }