亚洲欧洲国产欧美一区精品,激情五月亚洲色五月,最新精品国偷自产在线婷婷,欧美婷婷丁香五月天社区

      考試首頁 | 考試用書 | 培訓(xùn)課程 | 模擬考場 | 考試論壇  
      全國  |             |          |          |          |          |         
        當(dāng)前位置:計算機等級 > 二級考試 > Java語言程序設(shè)計 > 模擬試題 > 文章內(nèi)容
        

      全國計算機等級考試二級Java模擬試題及答案(29)

      中華IT學(xué)院   【 】  [ 2016年11月22日 ]
      1、編寫程序,計算下列分段函數(shù)的值。
      x? (x>=0)
      y=
      -x? (x<0)
      import java.io.*;
      public class testa
      { public static void main(String[] args) throws IOException
      {
      float? x,y;
      InputStreamReader reader=new InputStreamReader(System.in);
      BufferedReader input=new BufferedReader(reader);
      System.out.println("請輸入x:");
      String temp=input.readLine();
      x = Float.parseFloat(temp);
      if(x>=0)
      {
      y=x;
      }else
      {
      y=-x;
      }
      System.out.println("y="+y);
      }
      }
      2、根據(jù)年齡,判斷某人是否為成年。
      import java.io.*;
      public class testa
      {
      public static void main(String[] args) throws IOException
      {
      int x;
      InputStreamReader reader=new InputStreamReader(System.in);
      BufferedReader input=new BufferedReader(reader);
      System.out.println("請輸入x:");
      String temp=input.readLine();
      x = Float.parseFloat(temp);
      if(x>=18)
      {
      System.out.println("成年人");
      }
      if(x<18)
      {
      System.out.println("未成年");
      }
      }
      }
      3、判斷2020的奇偶性,并進行輸出。
      public class test
      {
      public static void main(String[] args)
      {
      int x;
      x=2020;
      if(x%2==0)
      System.out.println(+x+"是偶數(shù)");
      else
      System.out.println(+x+"不是偶數(shù)");
      }
      }
      4、比較兩個數(shù)的大小,找出其中的最大數(shù)并輸出。
      import java.io.*;
      public class ka
      { public static void main(String[] args) throws IOException
      {
      float? x,y,m;
      m=0;
      InputStreamReader readerx=new InputStreamReader(System.in);
      BufferedReader inputx=new BufferedReader(readerx);
      System.out.println("請輸入x:");
      String tempx=inputx.readLine();
      x = Float.parseFloat(tempx);
      InputStreamReader readery=new InputStreamReader(System.in);
      BufferedReader inputy=new BufferedReader(readery);
      System.out.println("請輸入y:");
      String tempy=inputy.readLine();
      y= Float.parseFloat(tempy);
      if(x>y)
      {
      m=x;
      }else
      {
      m=y;
      }
      System.out.println("最大數(shù)為"+m);
      }
      }
      5、比較兩個數(shù)的大小,找出其中的最小數(shù)并輸出。
      import java.io.*;
      public class ka
      { public static void main(String[] args) throws IOException
      {
      float? x,y,m;
      m=0;
      InputStreamReader readerx=new InputStreamReader(System.in);
      BufferedReader inputx=new BufferedReader(readerx);
      System.out.println("請輸入x:");
      String tempx=inputx.readLine();
      x = Float.parseFloat(tempx);
      InputStreamReader readery=new InputStreamReader(System.in);
      BufferedReader inputy=new BufferedReader(readery);
      System.out.println("請輸入y:");
      String tempy=inputy.readLine();
      y= Float.parseFloat(tempy);
      if(x{
      m=x;
      }else
      {
      m=y;
      }
      System.out.println("最小數(shù)為"+m);
      }
      }
      6、編寫一個Java程序,判斷某年份是否為閏年。
      import java.io.*;
      public class testa
      {
      public static void main(String[] args) throws IOException
      {
      float? x;
      InputStreamReader reader=new InputStreamReader(System.in);
      BufferedReader input=new BufferedReader(reader);
      System.out.println("請輸入x:");
      String temp=input.readLine();
      x =Float.parseFloat(temp);
      if(x@0==0)
      {
      System.out.println(+x+"是閏年");
      }
      else
      if(x%4==0)
      {
      System.out.println(+x+"是閏年");
      }
      else{ System.out.println(+x+"不是閏年");}
      }
      }
      7、比較兩個數(shù)的大小,找出其中的最大數(shù)和最小數(shù)并輸出。
      import java.io.*;
      public class ka
      { public static void main(String[] args) throws IOException
      {
      float? x,y;
      InputStreamReader readerx=new InputStreamReader(System.in);
      BufferedReader inputx=new BufferedReader(readerx);
      System.out.println("請輸入x:");
      String tempx=inputx.readLine();
      x = Float.parseFloat(tempx);
      InputStreamReader readery=new InputStreamReader(System.in);
      BufferedReader inputy=new BufferedReader(readery);
      System.out.println("請輸入y:");
      String tempy=inputy.readLine();
      y= Float.parseFloat(tempy);
      if(x{
      System.out.println("最小數(shù)為"+x);
      System.out.println("最大數(shù)為"+y);
      }else
      {
      System.out.println("最小數(shù)為"+y);
      System.out.println("最大數(shù)為"+x);
      }
      }
      }
      8、比較兩個數(shù)的大小,找出其中的最大數(shù)和最小數(shù),并輸出最大數(shù)和最小數(shù)之差。
      import java.io.*;
      public class ka
      { public static void main(String[] args) throws IOException
      {
      float? x,y,m;
      InputStreamReader readerx=new InputStreamReader(System.in);
      BufferedReader inputx=new BufferedReader(readerx);
      System.out.println("請輸入x:");
      String tempx=inputx.readLine();
      x = Float.parseFloat(tempx);
      InputStreamReader readery=new InputStreamReader(System.in);
      BufferedReader inputy=new BufferedReader(readery);
      System.out.println("請輸入y:");
      String tempy=inputy.readLine();
      y= Float.parseFloat(tempy);
      if(x{
      System.out.println("最小數(shù)為"+x);
      System.out.println("最大數(shù)為"+y);
      首頁 1 2 尾頁
      分享到:
      本文糾錯】【告訴好友】【打印此文】【返回頂部
      將考試網(wǎng)添加到收藏夾 | 每次上網(wǎng)自動訪問考試網(wǎng) | 復(fù)制本頁地址,傳給QQ/MSN上的好友 | 申請鏈接 | 意見留言 TOP
      關(guān)于本站  網(wǎng)站聲明  廣告服務(wù)  聯(lián)系方式  站內(nèi)導(dǎo)航  考試論壇
      Copyright © 2007-2013 中華考試網(wǎng)(Examw.com) All Rights Reserved