求各位为小弟解惑,怎样可以实现:
输入字符串,字符串中有数字,将数字对应的字符打印;
小弟哪里出错了:import java.io.*;
public class Test {
public static void main(String args[])throws IOException{
int i;
char c='0';
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
for(;;){
System.out.println(">");
String s=in.readLine();
for(i=0;i<s.length();i++){
c+=s.charAt(i);
}
if((c>='0')&&(c<='9'))
System.out.print(s.charAt(c));
}
}
}
输入字符串,字符串中有数字,将数字对应的字符打印;
小弟哪里出错了:import java.io.*;
public class Test {
public static void main(String args[])throws IOException{
int i;
char c='0';
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
for(;;){
System.out.println(">");
String s=in.readLine();
for(i=0;i<s.length();i++){
c+=s.charAt(i);
}
if((c>='0')&&(c<='9'))
System.out.print(s.charAt(c));
}
}
}
解决方案 »
- 报错....表或者视图不存在。
- 对2个ArrayList集合下的值进行比较~
- 使用J2EE 1.4自带的工具打包的EJB ,老是提示失败,无法装载类,是怎么回事啊。
- What method call is used to tell a thread that it has the opportunity to run?
- 请教有JAVA工作经验的我该如何学习JAVA!
- Java 实现快速平方根
- 加载图象的问题!!!!求你了,告诉我吧!!!
- 一道SCJP的垃圾收集器的问题.
- 请问JAVA用什么工具编写比较好啊?还有JAVA的SDK从哪里下载比较快?
- 为OCJP盖个楼!(Welcome everyone~)
- (100分求)实现一个算法
- 请问java中的对象克隆一般用在什么时候????
public class Test {
public static void main(String args[])throws IOException{
int i;
char c = '0';
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
for(;;){
System.out.println(">");
String s=in.readLine();
for(i=0;i <s.length();i++){
c = s.charAt(i);
if((c>='0')&&(c <='9'))
System.out.print(c);
}
}
}
}
char c = '0';
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s = in.readLine();
for (i = 0; i < s.length(); i++) {
c = s.charAt(i);
if ((c >= '0') && (c <= '9'))
System.out.print(c);
}
import java.io.*;
public class CharTest { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
int i;
char c='0';
BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); while(true){
System.out.println(">");
String s;
s = in.readLine();
for(i=0;i<s.length();i++){
c=s.charAt(i);
if((c>='0')&&(c<='9'))
System.out.print(c);
}
}
}catch(IOException e){
e.printStackTrace();
}
}}
import java.io.*;
public class Test {
public static void main(String args[])throws IOException{
int i;
char c = '0';
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
for(;;){
System.out.println(">");
String s=in.readLine();
for(i=0;i <s.length();i++){
c = s.charAt(i);
if((c>='0')&&(c <='9'))
System.out.print(c);
}
}
}
}这样好看点
shyhappyaa 1 6 h p
直接print(c)出来的只可能是数字嘛!仍感谢各位帮助
import java.io.*; public class Test1 {
public static void main(String args[])throws IOException{
int i; BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
for(;;){
System.out.println(">");
String s = in.readLine(); for(i=0; i<s.length(); i++){
char c = s.charAt(i); if((c>='0')&&(c <='9'))
System.out.print(c);
}
}
}
}
>
111
111>
22222222
22222222>
2dsad4
24>
public class Test {
public static void main(String args[])throws IOException{
int i;
char c = '0';
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
for(;;){
System.out.println(">");
String s=in.readLine();
for(i=0;i <s.length();i++){
c = s.charAt(i);
if((c>='0')&&(c <='9')){
int k = Integer.parseInt(String.valueOf(s.charAt(i)));
System.out.print(s.charAt(k));
}
}
}
}
}是不是这样?
C:\Documents and Settings\Administrator>java Test
>
quest12
ue>
skjdlkfjsdjfk78
js>