编写完整的JAVA应用程序,求任意一个整形数和实型数的和、差、积与商?

编写完整的JAVA应用程序,求任意一个整形数和实型数的和、差、积与商?,第1张

import java.util.Scanner

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

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7996633.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-12
下一篇 2023-04-12

发表评论

登录后才能评论

评论列表(0条)

保存