zoukankan      html  css  js  c++  java
  • 作业

    1.控制台输入年龄,根据年龄输出不同提示。

    import java.util.Scanner;

    public class zuoye {

    public static void main(String[] args) {
    // TODO 自动生成的方法存根
    Scanner sc=new Scanner(System.in);
    System.out.print("请输入年龄:");
    double age=sc.nextDouble();
    if(age%1==0&age>=0&age<=135)
    {
    int a=(int)age;
    if(a<21)
    {
    System.out.println("儿童");
    }
    else if(a<31)
    {
    System.out.println("青年");
    }
    else if(a<51)
    {
    System.out.println("中年人");
    }
    else
    {
    System.out.println("老年人");
    }
    }
    else
    {
    System.out.println("请输入正确地年龄");
    }

    }

    }

    2. 控制台输出三角形和菱形

    public class zuoye2{

    public static void main(String[] args) {


    for(int i=1;i<10;i++)
    {

    for(int k=9;k>i;k--)
    {
    System.out.print(" ");
    }
    for(int l=1;l<i+1;l++)
    {
    System.out.print("*");
    }
    for(int l=1;l<i+1;l++)
    {
    System.out.print("*");
    }
    System.out.println("");
    }
    for(int i=1;i<10;i++)
    {
    for(int k=1;k<i;k++)
    {
    System.out.print(" ");
    }
    for(int j=9;j>i-1;j--)
    {
    System.out.print("*");
    }
    for(int j=9;j>i-1;j--)
    {
    System.out.print("*");
    }
    System.out.println("");
    }

    }

    }

    3.九九乘法表

    public class zuoye3{
    public static void main (String[]args){

    for(int i = 1;i < 9; i++)
    {
    for(int j = 1; j <=i ; j++)
    {
    System.out.print(j+""+"*"+i+"="+i*j+" ");
    }
    System.out.println("");
    }
    }
    }

    4.百马百担

    100匹马驮100担货,大马驮3担,中马驮2担,小马两个驮一担;问有大中小马个几匹?

    public class zuoye3

    {
    public static void main(String[] args)
    {
    for(int i = 0;i < 33;i++)
    {
    for(int x =0; x<=50;x++)
    {
    for(int y = 0;y <=100;y++)
    {
    if(i+x+y)==100&&(i*3+x*2+y/2)==100&&(y%2==0)
    {
    System.out.println("大马数量:"+i+",中马数量:"+x+"小马数量:"+y);
    }
    }
    }
    }
    }
    }

  • 相关阅读:
    MySQL_创建数据库和表
    MySQL注释的3中方法
    子查询概念和分类
    弱网测试如何进行
    Fiddler_ 移动端抓包配置IOS&Android,Fiddler获取APP端的流量
    Fiddler_HTTPS 如何抓包和浏览器设置
    Fiddler_弱网测试
    Three.js 游戏操作案例
    flex 教程
    JS知识
  • 原文地址:https://www.cnblogs.com/smile-dream/p/5868490.html
Copyright © 2011-2022 走看看