zoukankan      html  css  js  c++  java
  • 第一、二次实训作业

    1.编写程序:

      声明一个整型变量a,并赋初值5,在程序中判断a是奇数还是偶数,然后输出判断的结果。

    package 判断奇偶;

    public class liux {

         public static void main(String[] args){

         int x=5;

         if(x%2==0){

         System.out.println("这个数为偶数");

         }else    System.out.println("这个数为奇数");

         }

    }

    2.编写程序:从键盘输入圆的半径,计算圆的面积并输出。

    package 计算圆的面积;
    import java.util.Scanner;
    public class liux {
     static final double PI =  3.14159;
     public static void main(String[] args){
      Scanner scanner=new Scanner(System.in);
      int r;
      System.out.println("请输入圆的半径:");
      r=scanner.nextInt();
      System.out.println("圆的面积为:"+PI*r*r);
      scanner.close();
     }
    }

    3.编写程序:实现一个数字加密器。运行时输入加密前的整数,通过加密运算后,输出加密后的结果,加密结果仍为一整数。

    package 加密器;
    import java.util.Scanner;
    public class liux {
        public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int x;
        System.out.println("请输入加密前的数字:");
        x=scanner.nextInt();
        int n;
        n=(int) ((x*10+5)/2+3.1415926);
        System.out.println("加密后的数字为:"+n);
        scanner.close();
     }
    }

    4.声明并创建存放4个人考试成绩的一维数组,并使用for循环遍历数组并打印分数。要求:

    • 首先按“顺序”遍历,即打印顺序为:从第一个人到第四个人;
    • 然后按“逆序”遍历,即打印顺序为:从从第四个人到第一个人;
    • 输出最高分; 
    • 输出最低分;

    package 一维数组;
    import java.util.Scanner;
    public class liux {
     @SuppressWarnings("resource")
     public static void main(String[] args){
      int student[]=new int[5];
      int i;
      Scanner score=new Scanner(System.in);
      for(i=4;i>0;i--){
      student[i]=score.nextInt();
      System.out.println("第"+i+"个学生的成绩为:"+student[i]);
      }   int max=student[1];
      int min=student[1];
      for(i=1;i<5;i++){
       if(max<student[i])    max=student[i];
      }   if(min>student[i])    min=student[i];
     } }

  • 相关阅读:
    函数方法与面向对象
    seleniums私房菜系列一 ---- selenium简介
    MySQL图形化管理工具
    存储引擎
    mysql自定义函数
    加密函数
    mysql聚合函数
    mysql信息函数
    mysql日期时间函数(常用的)
    mysql比较运算符和函数
  • 原文地址:https://www.cnblogs.com/liuxun1031/p/10695214.html
Copyright © 2011-2022 走看看