public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in)
int n = sc.nextInt()
while(n <100 || n >999){
System.out.println("对不起,您的输入有误,请重新输入一个三位数:")
n = sc.nextInt()
}
int a = n%10//a是个位数;
int b = (n%100)/10//b是十位数;
int c = n/100//c是百位数;
int sum = a + b + c
System.out.println("百位数是:"+c+"\t十位数是:"+b+"\t个位数是:"+a)
System.out.println("各位相加之和是:"+ sum)
}
}
public class Test {public static void main(String[] args) {
Student student1 = new Student()
Student student2 = new Student("王二")
student1.show()
student2.show()
student1.setName("李四")
student2.setName("赵六")
student1.show()
student2.show()
}
}
interface Person {
void show()
}
class Student implements Person {
private String name
public Student() {
name = "王二"
}
public Student(String name) {
super()
this.name = name
}
public void show() {
System.out.printf("name=%s\n", name)
}
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)