| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 487 人关注过本帖
标题:[求助] java标识符错误
只看楼主 加入收藏
yfann
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-3-23
收藏
 问题点数:0 回复次数:3 
[求助] java标识符错误

package study;
import java.util.Scanner;
public class NameUse{
public static void main (String[] args){
System.out.println("Please enter your name:");
Name test= new Name();
System.out.println("Your Name is "+test.toString()+"!");
}

}
class Name
{ Scanner keyboard=new Scanner(System.in);
private String firstname =keyboard.next();
private String lastname =keyboard.next();
firstname=firstname.toLowerCase();//******************************1
lastname=lastname.toLowerCase();//********************************2
public void setFirstName(String firstname)
{this.firstname = firstname;
}
public String getFirstName()
{return this.firstname;
}
public void setLastrName(String lastname)
{this.lastname = lastname;
}
public String getLastName()
{return this.lastname;
}
String fs,ls,fn,ln,fl,ll;
public String toString(){
fs=firstname.substring(1,2);
fs=fs.toUpperCase();
ls=lastname.substring(1,2);
ls=ls.toUpperCase();
fn=firstname.substring(2);
ln=lastname.substring(2);
fl=fs+fn+firstname.substring(0,1)+"ay";
ll=ls+ln+lastname.substring(0,1)+"ay";
return fl+" "+ll;
}
}
为什么在编译时1,2处发生'需要标识符'错误

搜索更多相关主题的帖子: java 符错误 
2007-04-12 12:27
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
以下是引用yfann在2007-4-12 12:27:12的发言:

package study;
import java.util.Scanner;
public class NameUse{
public static void main (String[] args){
System.out.println("Please enter your name:");
Name test= new Name();
System.out.println("Your Name is "+test.toString()+"!");
}

}
class Name
{ Scanner keyboard=new Scanner(System.in);
private String firstname =keyboard.next();
private String lastname =keyboard.next();
firstname=firstname.toLowerCase();//******************************1
lastname=lastname.toLowerCase();//********************************2
public void setFirstName(String firstname)
{this.firstname = firstname;
}
public String getFirstName()
{return this.firstname;
}
public void setLastrName(String lastname)
{this.lastname = lastname;
}
public String getLastName()
{return this.lastname;
}
String fs,ls,fn,ln,fl,ll;
public String toString(){
fs=firstname.substring(1,2);
fs=fs.toUpperCase();
ls=lastname.substring(1,2);
ls=ls.toUpperCase();
fn=firstname.substring(2);
ln=lastname.substring(2);
fl=fs+fn+firstname.substring(0,1)+"ay";
ll=ls+ln+lastname.substring(0,1)+"ay";
return fl+" "+ll;
}
}
为什么在编译时1,2处发生'需要标识符'错误

直接类体里面是不能做别的事情的,只能赋值,而不能涉及到方法的调用

import java.util.Scanner;
public class NameUse{
public static void main(String[] args){
System.out.println("Please enter your name:");
Name test= new Name();
System.out.println("Your Name is "+test.toString()+"!");
}

}
class Name {
Scanner keyboard=new Scanner(System.in);
private String firstname =keyboard.next().toLowerCase();
private String lastname =keyboard.next().toLowerCase();

public void setFirstName(String firstname) {
this.firstname = firstname;
}
public String getFirstName() {
return this.firstname;
}
public void setLastrName(String lastname) {
this.lastname = lastname;
}
public String getLastName() {
return this.lastname;
}
String fs,ls,fn,ln,fl,ll;
public String toString(){
fs=firstname.substring(1,2);
fs=fs.toUpperCase();
ls=lastname.substring(1,2);
ls=ls.toUpperCase();
fn=firstname.substring(2);
ln=lastname.substring(2);
fl=fs+fn+firstname.substring(0,1)+"ay";
ll=ls+ln+lastname.substring(0,1)+"ay";
return fl+" "+ll;
}
}


可惜不是你,陪我到最后
2007-04-12 13:56
yfann
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-3-23
收藏
得分:0 
真是太感谢了
2007-04-12 14:38
skylence
Rank: 1
等 级:新手上路
帖 子:92
专家分:0
注 册:2006-11-15
收藏
得分:0 

运行发生异常!


2007-04-12 17:35
快速回复:[求助] java标识符错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027394 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved