<delect id="sj01t"></delect>
  1. <em id="sj01t"><label id="sj01t"></label></em>
  2. <div id="sj01t"></div>
    1. <em id="sj01t"></em>

            <div id="sj01t"></div>

            java考試模擬試題

            時間:2024-05-31 23:50:55 JAVA認證 我要投稿

            2017年java考試模擬試題

              Sun 公司在推出 Java 之際就將其作為一種開放的技術。全球數以萬計的 Java 開發公司被要求所設計的 Java 軟件必須相互兼容。下面是小編整理的關于java考試模擬試題,希望大家認真閱讀!

            2017年java考試模擬試題

              1、編寫程序,計算下列分段函數的值。

              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、根據年齡,判斷某人是否為成年。

              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+"是偶數");

              else

              System.out.println(+x+"不是偶數");

              }

              }

              4、編寫程序,計算10的階乘并輸出運算結果。

              public class a

              {

              public static void main(String[] args)

              {

              int i,s=1;

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

              {

              s=s*i;

              }

              System.out.println("10的階乘是"+s);

              }}

              5、編寫程序,計算1、2、3...的累加和,條件是和小于50。

              public class a

              {

              public static void main(String[] args)

              {

              int i=1,s=0;

              label:

              while(true)

              {? s=s+i;

              i++;

              if(s>50)

              { s=s+1-i;

              break;}}

              System.out.println("從1開始的累加和小于50的累加和是"+s);

              }}

              6、編寫程序,計算偶數2、4、6...的累加和,條件是和小于50。

              public class a

              {

              public static void main(String[] args)

              {

              int i=1,s=0;

              label:

              while(true)

              {? s=s+2*i;

              i++;

              if(s>50)

              { s=s-2*i+2*1;

              break;}}

              System.out.println("從2開始的偶數累加和小于50的累加和是"+s);

              }}

              7、編寫程序,輸出下列圖案:

              *

              ***

              *****

              *******

              public class a

              {???????? public static void main(String[] args)

              { int i,k;

              for(i=1;i<=4;i++)

              {

              for(k=1;k<=2*i-1;k++)

              System.out.print("*");

              System.out.println();

              }

              }

              }

              8、編寫程序,輸出下列圖案:

              *

              ***

              *****

              *******

              public class a

              {???????? public static void main(String[] args)

              { int i,j,k;

              for(i=1;i<=4;i++)

              {

              for(j=1;j<=8-2*i;j++)

              System.out.print(" ");

              for(k=1;k<=2*i-1;k++)

              System.out.print("*");

              System.out.println();

              }

              }

              }

              9、編寫程序,輸出下列圖案:

              *******

              *****

              ***

              *

              public class a

              {???????? public static void main(String[] args)

              { int i,j,k;

              for(i=1;i<=4;i++)

              {

              for(j=1;j<=2*i-2;j++)

              System.out.print(" ");

              for(k=1;k<=9-2*i;k++)

              System.out.print("*");

              System.out.println();

              }

              }

              }

              10、編寫程序在終端打印1~100之間的素數。

              public class a

              {???????? public static void main(String[] args)

              { int i,j;

              label:

              for(i=2;i<=100;i++)

              {????? for(j=2;jif(i%j==0)

              continue label;

              System.out.print(+i);

              System.out.println();

              }

              }

              }

              11、編寫一個java程序,用窮舉法找出2~50之間的素數,并打印出來。

              public class s{

              public static void main(String args[]){

              int i,j,k ;

              boolean flag ;

              for (i=2;i<=50 ;i++ ){

              flag =true ;

              k=i/2 ;

              for (j=2;j<=k ;j++ ){

              if (i%j==0){

              flag = false ;

              break ;

              }

              }

              if (flag){

              System.out.println(i+"") ;

              }

              }

              }

              }

              12、編寫一自定義方法,找出兩個數中的最大數,并main方法中驗證。

              public class a

              {

              static double Max(double x,double y)

              {?? double t;

              if(x>=y)

              {

              t=x;

              }else

              { t=y;???? }

              return t;

              }

              public static void main(String[] args)

              {

              double x,y,m;

              x=549.265;

              y=56.28;

              m =Max(x,y);

              System.out.println("最大數是"+m);

              System.out.println("x="+x+"y="+y);

              if(m>=x&&y<=m)

              {

              System.out.println("ture");

              }

              else

              {

              System.out.println("flase");

              }

              }

              }

              13、編寫一自定義方法,找出兩個數中的最小數,并main方法中驗證。

              public class a

              {

              static double Min(double x,double y)

              {?? double t;

              if(x<=y)

              {

              t=x;

              }else

              { t=y;???? }

              return t;

              }

              public static void main(String[] args)

              {

              double x,y,m;

              x=245.38;

              y=525.63;

              m =Min(x,y);

              System.out.println("最小數是"+m);

              System.out.println("x="+x+"y="+y);

              if(m<=x&&y>=m)

              {

              System.out.println("ture");

              }

              else

              {

              System.out.println("flase");

              }

              }

              }

              14、編程,找出長度為10的數組中,數組元素的最大值,并輸出。

              public class a

              {

              public static void main(String[] args)

              {

              double x[]={25.3,56.3,15.3,125.25,465.36,456.32,458.21,456.325,4856.3215,41.6};

              double m= x[0];

              int i;

              for(i=0;i<10;i++)

              { if (m<=x[i])

              m=x[i];

              }

              System.out.println("最大數是"+m); }}

              15、編程,找出長度為10的數組中,數組元素的最小值,并輸出。

              public class a

              {

              public static void main(String[] args)

              {

              double x[]={25.3,56.3,15.3,125.25,465.36,456.32,458.21,456.325,4856.3215,41.6};

              double m=x[0];

              int i;

              for(i=0;i<10;i++)

              { if (m>=x[i])

              m=x[i];

              }

              System.out.println("最小數是"+m); }}

              16、編程,找出長度為10\的數組中,數組元素的最大值和最小值,并輸出。

              public class a

              {

              public static void main(String[] args)

              {

              double x[]={25.3,56.3,15.3,125.25,465.36,456.32,458.21,456.325,4856.3215,41.6};

            【java考試模擬試題】相關文章:

            Java考試格林模擬試題03-23

            2017年java模擬試題03-06

            sun認證java基礎模擬試題03-30

            NIIT認證Java基礎全真模擬試題03-08

            java考試試題及答案10-25

            2017華為JAVA考試試題03-09

            java認證考試試題及答案03-04

            播音主持考試模擬試題01-20

            CPA考試模擬試題及答案10-24

            <delect id="sj01t"></delect>
            1. <em id="sj01t"><label id="sj01t"></label></em>
            2. <div id="sj01t"></div>
              1. <em id="sj01t"></em>

                      <div id="sj01t"></div>
                      黄色视频在线观看