NIIT认证Java基础全真模拟试题

发布时间:2016-11-09 00:00:00 编辑:嘉辉 手机版

  三.程序阅读题(每题4分,共28分)

  1.以下程序的输出结果为 。

  class StringTest1

  {

  public static void main(String[] args) {

  String s1="hello";

  String s2=new String("hello");

  if(s1.equals(s2)){

  System.out.println("相等"); }else{

  System.out.println("不相等"); }

  }

  } )

  2.以下程序段的输出结果为 。 public class TestArray

  {

  public static void main(String args[]) {

  int i, j;

  int a[] = { 5, 9, 6, 8, 7 };

  for (i = 0; i < a.length - 1; i++) {

  int k = i;

  for (j = i; j < a.length; j++) if (a[j] < a[k])

  k = j;

  int temp = a[i];

  a[i] = a[k];

  a[k] = temp;

  }

  for (i = 0; i < a.length; i++)

  System.out.print(a[i] + " "); System.out.println();

  }

  }

  3.阅读以下程序:

  public class Exp1

  {

  public static void main(String[] args) {

  String s, s1 = "";

  char c;

  s = args[0];

  for (int i = 0; i < s.length(); i++) {

  c = s.charAt(i);

  if (c >= 'a' && c <= 'z')

  {

  s1 = s1 + Character.toUpperCase(c); }

  else

  {

  s1 = s1 + Character.toLowerCase(c); }

  }

  System.out.println(s1);

  }

  }

  若在控制台输入:java Exp1 abcDEF,则输出为?

  4.以下程序段的输出结果为。

  public class IntORString

  {

  void iosM(int i)

  {

  System.out.println("int");

  }

  void iosM(String s)

  {

  System.out.println("String"); }

  public static void main(String args[]) {

  IntORString ios = new IntORString(); ios.iosM('a');

  ios.iosM('1');

  }

  }

  5.阅读以下程序,写出输出结果。

  class Animal

  {

  Animal()

  {

  System.out.print("Animal "); }

  }

  public class Dog extends Animal

  {

  Dog()

  {

  System.out.print("Dog");

  }

  public static void main(String[] args)

  {

  new Dog();

  }

  }

  6.写出以下程序的运行结果。

  public class ATest

  {

  public static void main(String args[]) {

  SubClass sb = new SubClass();

  System.out.println(sb.fun());

  }

  }

  class SuperClass

  {

  int a = 24, b = 5;

  }

  class SubClass extends SuperClass

  {

  int fun()

  {

  return a % b;

  }

  }

  7.写出以下程序的运行结果。

  public class TryCatchFinally

  {

  static void Proc(int sel)

  {

  try

  {

  if (sel == 0)

  {

  System.out.println("No Exception"); return;

  }

  else if (sel == 1)

  {

  int i = 0;

  int

  }

  }

  catch (ArithmeticException e)

  {

  System.out.println("Catch");

  }

  catch (Exception e)

  {

  System.out.println("Will not be executed");

  }

  finally

  {

  System.out.println("finally");

  }

  }

  public static void main(String args[])

  {

  Proc(0);

  Proc(1);

  }

  }

  四.编程题

  1. (6分)编写一程序,实现排序算法,将一个已知的double数组进行从大到小输出

  2.(8分)编写一个输出计算n!的程序。

下页更精彩:首页 上一页 1 2
本文已影响937
+1
0