[英]java assignment in string by using charAt()
import java.util.Scanner;
/**
* @(#)wefeqwrf.java
*
* wefeqwrf application
*
* @author
* @version 1.00 2013/11/15
*/
public class wefeqwrf {
public static void main(String[] args) {
// TODO, add your application code
Scanner scan= new Scanner(System.in);
String number = "000";
String a;
int count=0;
for(int i=0;a!="-1";i++)
{
for(int k=0;k<3;k++){
a=scan.next();
a.charAt(0)= number.charAt(k);
if(number.equals("110"))
{
System.out.print("Tebrikler!=110");
count++;
}
else
{
System.out.print("Maalesef olmadı:" + number);
}
}
}
}
}
It gives the error: 它给出了错误:
error: unexpected type at this code: `a.charAt(0)= number.charAt(k);`
how can I assign the content of a to the specified index of number? 如何将a的内容分配给指定的数字索引?
and when I changed the string a to the char a scan.next()
does not work why and what can I do is there a any scanner method for char? 当我将字符串a更改为char时, scan.next()
无法正常工作,我该怎么办?char是否有任何扫描程序方法?
You should do it this way: 您应该这样进行:
a = number.charAt(k) + a.substring(1);
You can't assign something to a method. 您不能为方法分配某些内容。 Methods only return something. 方法只会返回一些东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.