Write a program to enter 20 integer values in an array. Enter the value to be searched in this array. Using linear search method, find the position of the entered value in that array. Display an error message if the value is not in the array.
Question 2
Write a Java program to enter 20 values in an array. Pass this array
as
a
parameter
in
a
function
called
“sumEvenPositive( ).This function computes the sum of the elements that are even and positive.
1.求1000以内能被3,5和7中恰好两个整除的数,以10个为一行输出。
4. 以下的选项中能正确表示Java语言中的一个整型常量的是( )。
A) 12. B) -20 C) 1,000 D) 4 5 6 5. 以下选项中,合法的赋值语句是( )。
A) a = = 1; B) ++ i; C) a=a + 1= 5; D) y = int ( i );
6. 若所用变量都已正确定义,以下选项中,非法的表达式是( )。
A) a != 4||b==1 B) 'a' % 3 C) 'a' = 1/2 D) 'A' + 32
7. 若有定义int a = 2;则执行完语句a += a -= a * a; 后,a的值是( )。
A) 0 B) 4 C) 8 D) –4
8. 在Java语言中,逻辑常量只有true 和 ___________ 两个值。
9. Java语言中的浮点型数据根据数据存储长度和数值精度的不同,进一步分为float和 __________两种具体类型。
10. Java语言是( )。
A.面向问题的解释型高级编程语言 B.面向机器的低级编程语言 C.面向过程的编译型高级编程语言 D.面向对象的解释型高级编程语言 11. 下列的变量定义中,错误的是( )。
A) int i; B) int i=I
nteger.MAX_VALUE;
C) static int i=100; D) int 123_$;
12. 以下的变量定义语句中,合法的是( )。
A) float $_*5= 3.4F; B) byte b1= 15678;
C) double a =Double. MAX_VALUE; D) int _abc_ = 3721L;
13. 以下字符常量中不合法的是( )。
A) '|' B) '\\'' C) \ D) '我'
14. 若以下变量均已正确定义并赋值,下面符合Java语言语法的语句是( )。
A) b = a!=7 ; B) a = 7 + b + c=9;
C) i=12.3* % 4; D) a = a + 7 = c + b;
15. 下列程序段执行后t5的结果是( )。 int t1 = 9, t2 = 11, t3=8; int t4,t5;
t4 = t1 > t2 ? t1 : t2+ t1; t5 = t4 > t3 ? t4 : t3;
A) 8 B) 20 C) 11 D) 9
16. 设 a, b, c, d 均为 int 型的变量,并已赋值,下列表达式的结果属于非逻辑值的 是( )。
A) a!=b & c%d < a B) a++ = =a+b+c+d C) ++a*b--+d D) a+b>=c+d 17. 请说出下面程序的运行结果。 public static void main(String[] args) { int nNum1 = 6; int nNum2 = 8; System.out.println(); System.out.println(((nNum1 < nNum2) && (--nNum1) > nNum2)); System.out.println(\ System.out.println(((nNum1 < nNum2) && (--nNum1) > nNum2)); System.out.println(\}
2.下面程序的输出结果是什么? public class MyFirst { public static void main(String args[]) { int x = 1,y,total = 0; while(x <= 20) { y = x * x; System.out.println(“y = “ + y); total = total + y; ++x; } System.out.println(“Total is “ + total); } }
4.请指出下面程序的错误: swith(n) { case 1 :