导读:我写了一个更通用的 *** ,不限于3个字符的,任意长度的均可,权当交流:public static void main(String[] args) { // TODO Auto-generated method stub Scanner
我写了一个更通用的 *** ,不限于3个字符的,任意长度的均可,权当交流:
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(Systemin);
Systemoutprintln("请输入一个字符串:");
String str = inputnext();
Reverse(str);
}
public static void Reverse(String str){
Systemoutprintln("反转后的字符串为:");
for(int i = 0; i < strlength(); i++){
String temp = "";
temp = temp + strcharAt(strlength()-i-1);
Systemoutprint(temp);
}
我写了一个更通用的 *** ,不限于3个字符的,任意长度的均可,权当交流:
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(Systemin);
Systemoutprintln("请输入一个字符串:");
String str = inputnext();
Reverse(str);
}
public static void Reverse(String str){
Systemoutprintln("反转后的字符串为:");
for(int i = 0; i < strlength(); i++){
String temp = "";
temp = temp + strcharAt(strlength()-i-1);
Systemoutprint(temp);
}
package p1;
/
在主线程中开启3个子线程,分别实现打印字符串 012 345 678 (3) "ABC"-->"CBA"-->"BAC"
@author Administrator
/
public class OpenThreeThread_three extends Thread {
private static Object LOCK = new Object();
private static int p = 0;
private static int[] notifyarr = { 1, 2, 3, 3, 2, 1, 2, 1, 3 };
public static void main(String[] args) {
OpenThreeThread_three A = new OpenThreeThread_three() {
public void run() {
for (int i = 0; i < 3; i++) {
synchronized (LOCK) {
while (notifyarr[p] != 1) {
LOCKnotifyAll();
try {
LOCKwait();
} catch (InterruptedException e) {
eprintStackTrace();
}
}
Systemoutprintln("A" + i);
p++;
LOCKnotifyAll();
}
}
}
};
OpenThreeThread_three B = new OpenThreeThread_three() {
public void run() {
for (int i = 0; i < 3; i++) {
synchronized (LOCK) {
while (notifyarr[p] != 2) {
LOCKnotifyAll();
try {
LOCKwait();
} catch (InterruptedException e) {
eprintStackTrace();
}
}
Systemoutprintln("B" + i);
p++;
LOCKnotifyAll();
}
}
}
};
OpenThreeThread_three C = new OpenThreeThread_three() {
public void run() {
for (int i = 0; i < 3; i++) {
synchronized (LOCK) {
while (notifyarr[p] != 3) {
LOCKnotifyAll();
try {
LOCKwait();
} catch (InterruptedException e) {
eprintStackTrace();
}
}
Systemoutprintln("C" + i);
p++;
LOCKnotifyAll();
}
}
}
};
AsetName("A");
BsetName("B");
CsetName("C");
/
AsetPriority(4); BsetPriority(5); CsetPriority(3);
/
Astart();
Bstart();
Cstart();
}
}
int len(char str) {
int
length = -1;
for(int i = 0; str[i] != '\0'; i++)
{
length++;
}
return
length;
}
char reverse_str(char
str) {
int i = 0, j = len(str) -
1;
char temp;
while(i
< j) {
temp = str[i]; str[i] = str[j];
str[j] = temp;
i++; j--;
}
return str;
}
#include "stdioh"
#include "stringh"
main()
{
char str;
int i=0;
scanf("%s",str);
for(i=strlen(str)-1;i>=0;i--)
{
printf("%c",(str+i));
}
getch();
}
/
请输入字符串 : 123abc
123abccba321
请按任意键继续
/
#include <stdioh>
#include <stdlibh>
#include <stringh>
int main(int argc, char argv[]) {
char s[10];
int i,len;
printf("请输入字符串 : ");
scanf("%s",s);
len = strlen(s);
printf("%s",s);
for(i = len - 1; i >= 0; --i)
printf("%c",s[i]);
printf("\n");
system("PAUSE");
return 0;
}