编写完整的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)

}

}

MyShirt.java代码:

public class MyShirt {

//衣服长度

private double shirtLength

//袖子长度

private double sleeveLength

//颜色

private String color

//给定衣服长度

public double getShirtLength() {

return shirtLength

}

//获得衣服长度

public void setShirtLength(double shirtLength) {

this.shirtLength = shirtLength

}

//给定袖子长度

public double getSleeveLength() {

return sleeveLength

}

//获得袖子长度

public void setSleeveLength(double sleeveLength) {

this.sleeveLength = sleeveLength

}

//获得衣服颜色

public String getColor() {

return "green"

}

}

TestMyShirt.java代码

import java.util.Scanner

public class TestMyShirt {

public static void main(String[] args) {

MyShirt ms = new MyShirt()

System.out.print("请输入衣服长度:")

ms.setShirtLength(new Scanner(System.in).nextDouble())

System.out.print("请输入衣服袖子长度:")

ms.setSleeveLength(new Scanner(System.in).nextDouble())

System.out.println(" ")

System.out.println("该衣服参数如下:")

System.out.println("---------------")

System.out.println("衣服长度:"+ms.getShirtLength())

System.out.println("衣服袖子长度:"+ms.getSleeveLength())

System.out.println("衣服颜色:"+ms.getColor())

}

}

import java.util.Scanner

public class Text{

    public static void main(String args[]){

       System.out.println("请输入n")

       Scanner sc = new Scanner(System.in)

       int n= sc.nextInt()

       int t=1

       int i=1

       while(i<=n){

       t=i*t

       i=i+1

       }

       System.out.println("n!="+t)

       

       

    }

}

//补充,JAVA文件保存时文件名必须和类名相同。


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

原文地址: https://outofmemory.cn/yw/11834980.html

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

发表评论

登录后才能评论

评论列表(0条)

保存