import java.awt.event.ActionEvent;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
testJFrame frame=new testJFrame();
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class testJFrame extends JFrame{
private JTextField text1;
private JTextField text2;
private JTextField text3;
private JButton button;
private JPanel panel;
private static final int WIDTH=300;
private static final int HEIGHT=300;
public testJFrame(){
setTitle("test");
setSize(WIDTH,HEIGHT);
text1=new JTextField(12);
text2=new JTextField(12);
text3=new JTextField(12);
button=new JButton("确定");
button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
String str=text1.getText();
text2.setText(""+str.length());
for(int i=str.length()-1;i>=0;i--){
text3.setText(text3.getText()+str.charAt(i));
}
}
});
panel=new JPanel();
panel.add(text1);
panel.add(text2);
panel.add(text3);
panel.add(button);
add(panel);
}
}
因为写的比较赶,所以做的比较粗糙,不过你要的功能都有实现。
import java.util.Scanner;
public class Du3 {
public static void main(String[] args) {
System.out.println("Please input a piece of string:");
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
int count = str.length();
String reversedStr = new StringBuffer(str).reverse().toString();
System.out.println("Total " + count + " characters in '" + str + "'");
System.out.println(str + "-->reversed is: " + reversedStr);
}
}
-----------------------------------
Please input a piece of string:
abcdefghijklmn sdfsadlk2 23423423 sdf
Total 37 characters in 'abcdefghijklmn sdfsadlk2 23423423 sdf'
abcdefghijklmn sdfsadlk2 23423423 sdf-->reversed is: fds 32432432 2kldasfds nmlkjihgfedcba
import java.util.Scanner;
public class Test{
public static void main(String[] args){
System.out.println("请输入字符串:");
Scanner in = new Scanner(System.in);
String s = in.nextLine();
System.out.println("输入字符串长度为:"+s.length());
System.out.print("输入字符串反向输出为:");
for(int i = 0;i < s.length();i++){
System.out.print(s.substring(s.length()-i-1, s.length()-i));
}
}
}
运行结果:
请输入字符串:
abcdefg
输入字符串长度为:7
输入字符串反向输出为:gfedcba
就给你编写一个简单的程序看看,希望对你有帮助。
import java.io.*;
public class InputTest {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inputStr = "";
int n = 0;
System.out.println("请输入您的信息:");
while((inputStr = br.readLine()) != null){
n = inputStr.length();
System.out.println("您输入的信息个数是:"+n+"\n您所输入的信息内容是:"+inputStr);
System.out.println("请输入您的信息:");
}
}
}
运行结果为:
请输入您的信息:
4521
您输入的信息个数是:4
您所输入的信息内容是:4521
请输入您的信息:
sa
您输入的信息个数是:2
您所输入的信息内容是:sa
请输入您的信息:
您输入的信息个数是:0
您所输入的信息内容是:
请输入您的信息:
1445t;./'ghdf4
您输入的信息个数是:14
您所输入的信息内容是:1445t;./'ghdf4
请输入您的信息:
自己查文档,String类开发时天天用