java数组回文输出,例如:定义一个一维数组,无元素,从键盘录入(我爱中国),自动输出(国中爱我)的字 定义一个有10个元素的一维整型数组,从键盘输入给数组的每个元...
JAVA\u7f16\u7a0b\uff1a\u5b9a\u4e49\u4e00\u4e2a\u6574\u6570\u7c7b\u578b\u7684\u4e00\u7ef4\u6570\u7ec4\uff0c\u901a\u8fc7\u952e\u76d8\u7ed9\u6570\u7ec4\u5143\u7d20\u8d4b\u503c\u3002\u5e76\u5199\u4e00\u65b9\u6cd5f()\u5b9e\u73b0\u6570\u7ec4\u5143\u7d20\u4ece\u5c0f\u5230\u5927\u6392\u5217import java.util.Scanner;
public class test1 {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int[] a=new int[10];
for(int i=0;i<a.length;i++){
System.out.println("\u8bf7\u8f93\u5165"+a.length+"\u4e2a\u6570\u5b57,\u5f53\u524d\u7b2c"+(i+1)+"\u4e2a:");
a[i]=sc.nextInt();
}
System.out.print("\u6392\u5e8f\u524d\u6570\u7ec4\uff1a ");
for(int i:a){
System.out.print(i+"\t");
}
System.out.println();
new test1().f(a);
}
public void f(int[] a){
for(int i=a.length-1;i>0;i--){
for(int j=0;j<i;j++){
if(a[i]<a[j]){
int temp=a[i];;
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.print("\u6392\u5e8f\u540e\u7684\u6570\u7ec4\uff1a ");
for(int i:a){
System.out.print(i+"\t");
}
}
}
#include
printf("\u8bf7\u8f93\u516510\u4e2a\u6574\u6570\uff1a\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\n\u8f93\u5165\u768410\u4e2a\u6570\u662f\uff1a\n");
printf("\u8f93\u51fa\u4f60\u8f93\u5165\u7684\u5143\u7d20:\n");
for(int i=0;i<10;i++){
printf("arr[%d]=%d\n",i,arr[i]);
}
printf("\u6570\u7ec4\u603b\u548c\u4e3a:%d\n",sum);
}
\u4e0e\u7ed3\u6784\u6216\u7c7b\u4e2d\u7684\u5b57\u6bb5
\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u90fd\u5177\u6709\u76f8\u540c\u7c7b\u578b\uff08\u8fd9\u4e00\u70b9\u548c\u7ed3\u6784\u6216\u7c7b\u4e2d\u7684\u5b57\u6bb5\u4e0d\u540c\uff0c\u5b83\u4eec\u53ef\u4ee5\u662f\u4e0d\u540c\u7c7b\u578b\uff09\u3002\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u5b58\u50a8\u5728\u4e00\u4e2a\u8fde\u7eed\u6027\u7684\u5185\u5b58\u5757\u4e2d\uff0c\u5e76\u901a\u8fc7\u7d22\u5f15\u6765\u8bbf\u95ee\uff08\u8fd9\u4e00\u70b9\u4e5f\u548c\u7ed3\u6784\u548c\u7c7b\u4e2d\u7684\u5b57\u6bb5\u4e0d\u540c\uff0c\u5b83\u4eec\u901a\u8fc7\u540d\u79f0\u6765\u8bbf\u95ee\uff09\u3002
\u6570\u7ec4\u5143\u7d20\u5e76\u975e\u53ea\u80fd\u662f\u57fa\u5143\u6570\u636e\u7c7b\u578b\uff0c\u8fd8\u53ef\u4ee5\u662f\u7ed3\u6784\u3001\u679a\u4e3e\u6216\u7c7b\u3002
\u4ee5\u4e0a\u5185\u5bb9\u53c2\u8003\uff1a\u767e\u5ea6\u767e\u79d1-\u6570\u7ec4
public class Qk {
public static void main(String[] args){
int i;
System.out.println("请指明一维数组包含参数的个数:");
Scanner input=new Scanner(System.in);
int g=input.nextInt();
String SZ[]=new String[g];
for(i=0;i<SZ.length;i++){
System.out.println("请输入第"+(i+1)+"个参数");
SZ[i]=input.next();
}
for(i=g;i>0;i--){
System.out.print(SZ[i-1]);
}
}
}
翻转输出就行了啊:
假设定义的数组是a
for(int i=a.length-1;i>=0;i++){
system.out.print(a[i]);
}
绛旓細import java.util.Scanner;public class Qk { public static void main(String[] args){ int i;System.out.println("璇锋寚鏄庝竴缁鏁扮粍鍖呭惈鍙傛暟鐨勪釜鏁帮細");Scanner input=new Scanner(System.in);int g=input.nextInt();String SZ[]=new String[g];for(i=0;i<SZ.length;i++){ System.out.p...
绛旓細public static void main(String args[]) throws Exception { Scanner s = new Scanner(System.in);String str = s.next();print('a', str.charAt(0));} public static void print(char start, char end){ System.out.print(start);if(start<end)print((char)(start+1), end);System.o...
绛旓細import java.util.Scanner;public class Huiwen { public static void main(String[] args) { Scanner in = new Scanner(System.in);String num = in.next();if (num.matches("\\d+")) { //鏂规硶1 浣跨敤鏁扮粍 char[] nums = num.toCharArray();String num1="";for (int i = 0; i <...
绛旓細public class TestNumber { public static void main(String[] args) { for (int i = 1; i <= 10000; i++) { if (test(i)) { System.out.println(i);} } } private static boolean test(int i) { char c[] = String.valueOf(i).toCharArray();for (int j = 0; j < c.l...
绛旓細濡傛灉璇存槸鏁扮粍鍒ゆ柇锛屸滃井寰洖蹇嗏滅殑鏂规硶姝hВ銆 浣犱篃鍙互 鑷繁鍐欎釜鏂规硶 灏嗚緭鍏ョ殑鍊煎掔疆 鍒ゆ柇涓 鍘熷厛杈撳叆鐨勬槸鍚quals 銆傛渶绠鍗曠殑锛屾槸鍒╃敤java StringBuffer涓殑api銆 reverse瀹冨彲浠ュ皢涓涓瓧绗︿覆鍊掔疆銆 鐩存帴灏嗗掔疆鍚庣殑缁撴灉涓庡師鍏堢殑缁撴灉姣斿鍗冲彲 杩欎釜鏂规硶姣旇緝閫氱敤銆備絾鏄渶瑕佽浆鎹㈡垚瀛楃涓叉瘮杈冦
绛旓細浠g爜娌℃湁闂锛屾槸涓嶆槸浣犺緭鍏ョ殑鏁版嵁涓嶅锛熶互涓嬫槸杈撳叆鍙婅繍琛屾埅鍥撅細
绛旓細鎸夌収浣犵殑瑕佹眰缂栧啓鐨,杈撳嚭浠0鍒癿ax涓敤浜岃繘鍒惰〃绀哄拰鍗佽繘鍒惰〃绀洪兘鏄鍥炴枃鏁扮殑Java绋嬪簭濡備笅锛歩mport java.util.Scanner;public class CCF { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("璇疯緭鍏ヤ竴涓暣鏁帮細"); int max=sc.nextInt(); ...
绛旓細1銆佸彲浠ユ妸杩欎釜5涓暟鍒嗚В瀛樺湪涓涓鏁扮粍閲岄潰 2銆侀氳繃寰幆鍒ゆ柇鏄惁鐩哥瓑,寰簭娆℃暟灏辨槸闀垮害鏁撮櫎2 鍦ㄨ缃竴涓姸鎬佹爣璁,涓篢RUE灏辨槸鍥炴暟,涓篺alse灏变笉鏄,鍦ㄥ惊鐜腑,涓鏃︿笉鐩哥瓑灏辨妸鐘舵佹爣璁版敼涓篺alse,缁堟寰幆,褰撳惊鐜粨鏉熸椂,鐘舵佹爣璁拌繕鏄负true灏辨槸鍥炴暟銆 import java.util.Scanner; /* * 绗笁绔 java杩愮畻绗 * 璇惧悗...
绛旓細import java.util.Scanner;public class Exam01 { public static void main(String[] args) { Scanner scan = new Scanner(System.in);String temp;char[] arr;int i, j, len;//鎺ユ敹杈撳叆鐨勫瓧绗︿覆 temp = scan.nextLine();//灏嗗瓧绗︿覆temp涓殑鍏ㄩ儴瀛楃瀛樺叆瀛楃鏁扮粍arr涓 arr = temp.toCharArray...
绛旓細鎻愪緵鎬濊矾锛氬浜100鍒1000鐨勬瘡涓暟鍋氬涓嬪鐞嗭紱锛1锛夊皢璇ユ暟鍙樻垚瀛楃涓插悗鍊掔疆(string.reverse());锛2锛夊拰鍘熸暟杩涜姣旇緝锛岃嫢鐩稿悓锛屽垯鏄鍥炴枃鏁帮紝鍚﹀垯涓嶆槸