zoukankan      html  css  js  c++  java
  • 第五次作业

    分别使用for循环,while循环,do循环求1到100之间所有能被3整除的整数的和。(知识点:循环语句)

    package ydy3;

    import java.util.Scanner;

    public class test3 {

    public static void main(String[] args) {
    Scanner sc= new Scanner(System.in);
    System.out.println("请输入这个数的值");
    int sum=0;
    for(int i=0;i<=100;i++){
    if(i%3==0){
    //和sum变量进行累加
    sum+=i;
    }
    }
    System.out.println("1-100之间能被3整除的和是"+sum);

    }

    }

    package ydy3;

    import java.util.Scanner;

    public class test3 {

    public static void main(String[] args) {
    Scanner sc= new Scanner(System.in);
    System.out.println("请输入这个数的值");
    int sum=0;
    int i=0;
    while(i<=100){
    if(i%3==0){
    sum+=i;
    }
    i++;
    }
    System.out.println("1-100之间能被3整除的和是"+sum);
    }

    }

     输出0-9之间的数,但是不包括5。(知识点:条件、循环语句)

    package ydy3;

    import java.util.Scanner;

    public class test3 {

    public static void main(String[] args) {
    Scanner sc= new Scanner(System.in);
    System.out.println("请输入这个数的值");
    for(int i=0;i<=9;i++){
    if(i==5){
    continue;
    }
    System.out.print(i);
    }
    }

    }

      编写一个程序,求整数n的阶乘,例如5的阶乘是1*2*3*4*5(知识点:循环语句)

    package ydy3;

    import java.util.Scanner;

    public class test3 {

    public static void main(String[] args) {
    Scanner sc= new Scanner(System.in);
    System.out.println("请输入这个数的值");
    int n = input.nextInt();
    int x=1;
    int y=n;
    for(int i=0;i<n;i++){
    y=n-i;
    x=y*x;
    }
    System.out.println("n的阶乘为:"+x);
    }

    }

    编写一个程序,输入任意学生成绩,如果输入不合法(<0或者>100),提示输入错误,重新输入,直到输入合法程序结束(知识点:循环语句)

    package ydy3;

    import java.util.Scanner;

    public class test3{
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner input=new Scanner(System.in);
    for(int i=1;;i++){
    System.out.println("请输入一位学生成绩");
    int score=input.nextInt();
    if(score<0||score>100){
    System.out.println("输入成绩有误,请重新输入:");
    }else{
    System.out.println("该学生成绩为:"+score);
    break;
    }
    }
    }
    }

    假设某员工今年的年薪是30000元,年薪的年增长率6%。编写一个Java应用程序计算该员工10年后的年薪,并统计未来10年(从今年算起)总收入。(知识点:循环语句)

    package ydy3;

    import java.util.Scanner;

    public class test3{
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner input=new Scanner(System.in);
    double x=30000;
    double sum=0;
    for(int year=1;year<=10;year++){
    x=x*1.06;
    sum+=x;
    }
    System.out.println("员工10年后的年薪为:"+x);
    System.out.println("员工未来10年总收入为:"+sum);
    }
    }

  • 相关阅读:
    微信授权,重定向两次
    Newtonsoft.Json 序列化 排除指定字段或只序列化指定字段
    各大快递公司面单号准确性验证的正则表达式,来自淘宝开放平台,时间是20181206,
    微信小程序web-view(webview) 嵌套H5页面 唤起微信支付的实现方案
    HTTP请求头及其作用 转
    sql server 只读帐号设置能读取存储过程,view等内容。
    PhantomJS命令行选项
    XML实体注入漏洞
    XmlDocument 避免XXE
    Centos7.6安装redis
  • 原文地址:https://www.cnblogs.com/ydy128/p/12617376.html
Copyright © 2011-2022 走看看