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 abstract class Shape {public abstract double Area()
public abstract void printArea()
}
class Circle extends Shape {
int radius
public Circle(int radius) {
this.radius = radius
}
@Override
public double Area() {
return Math.pow(this.radius, 2) * Math.PI
}
@Override
public void printArea() {
// String.format("%.2f", Area()) 保留两位小数
System.out.println("半径为 " + this.radius + " 的圆的面积是 " + String.format("%.2f", Area()))
}
}
class Test {
public static void main(String[] args) {
// 生成一个 1 - 9 的随机整数
int radius = (int) (Math.random() * 9) + 1
// 创建一个 Circle 对象实例
Circle circle = new Circle(radius)
// 调用 printArea() 方法打印面积
circle.printArea()
}
}
public class User {private String userName
private String password
private static int userNumber
public User(){
userNumber++
this.userName="unKnown"
this.password="123456"
}
public User(String userName){
userNumber++
this.userName=userName
this.password="123456"
}
public User(String userName,String password){
userNumber++
this.userName=userName
this.password=password
}
public void setPassword(String oldPassword,String newPassword){
if(this.password.equals(oldPassword)){
this.password=newPassword
System.out.println("Password set success")
}else{
System.out.println("Password set not success")
}
}
public String toString(){
return "UserName:"+this.userName+" Password:"+this.password
}
}
public class TestUser {
public static void main(String[] args){
User u=new User()
System.out.println(u)
System.out.println("请输入密码:")
Scanner s=new Scanner(System.in)
String old=s.nextLine()
System.out.println("请输入新的密码:")
String newp =s.nextLine()
u.setPassword(old, newp)
System.out.println(u)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)