第一章 JAVA基础(7)

2019-08-29 00:17

4、 下面的示例程序说明了模运算符%的用法,写出以下程序的运行结果: public class Modulus {

public static void main(String args[]) { int x = 42;

double y = 42.25;

System.out.println(\System.out.println(\} }

该程序的输出结果为: 5、 下面的例子显示了几个赋值运算符的作用,写出以下程序的运行结果:

// Demonstrate several assignment operators. public class OpEquals {

public static void main(String args[]) { int a = 1; int b = 2; int c = 3; a += 5; b *= 4; c += a * b; c %= 6;

System.out.println(\System.out.println(\System.out.println(\} }

该程序的输出结果为: 6、 下面的程序说明了递增运算符的使用,写出以下程序的运行结果:

public class IncDec {

public static void main(String args[]) { int a = 1;

int b = 2; int c; int d; c = ++b; d = a++; c++;

System.out.println(\System.out.println(\System.out.println(\System.out.println(\} }

该程序的输出结果为:

7、 下面的例子说明了位逻辑运算符,写出以下程序的运行结果:

public class BitLogic {

public static void main(String args[]) {

String binary[] = { \

\\int a = 3; // 0 + 2 + 1 or 0011 in binary int b = 6; // 4 + 2 + 0 or 0110 in binary int c = a | b; int d = a & b; int e = a ^ b;

int f = (~a & b) | (a & ~b); int g = ~a & 0x0f;

System.out.println(\System.out.println(\System.out.println(\System.out.println(\System.out.println(\

System.out.println(\System.out.println(\} }

该程序的输出结果为:

8、 下面的示例程序说明了左移运算符的用法,写出以下程序的运行结果: public class ByteShift {

public static void main(String args[]) { byte a = 64, b; int i;

i = a << 2;

b = (byte) (a << 2);

System.out.println(\System.out.println(\} }

该程序的输出结果为: 9、 下面的示例程序说明了右移运算符的用法,写出以下程序的运行结果: public class HexByte {

static public void main(String args[]) {

char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

byte b = (byte) 0xf1;

System.out.println(\hex[b & 0x0f]); } }

该程序的输出结果为: 10、 下面的示例程序说明了位运算符的用法,写出以下程序的运行结果:

public class OpBitEquals {

public static void main(String args[]) { int a = 1; int b = 2; int c = 3; a |= 4; b >>= 1; c <<= 1; a ^= c;

System.out.println(\System.out.println(\System.out.println(\} }

该程序的输出结果为:

11、 下面的示例程序说明了布尔型运算符的用法,写出以下程序的运行结果: public class BoolLogic {

public static void main(String args[]) { boolean a = true; boolean b = false; boolean c = a | b; boolean d = a & b; boolean e = a ^ b;

boolean f = (!a & b) | (a & !b); boolean g = !a;

System.out.println(\System.out.println(\System.out.println(\System.out.println(\System.out.println(\

System.out.println(\System.out.println(\} }

该程序的输出结果为:

12、 下面的示例程序说明了?运算符的用法,写出以下程序的运行结果: public class Ternary {

public static void main(String args[]) { int i, k; i = 10;

k = i < 0 ? -i : i; // get absolute value of i System.out.print(\System.out.println(i + \i = -10;

k = i < 0 ? -i : i; // get absolute value of i System.out.print(\System.out.println(i + \} } 该程序的输出结果为:

13、写出下面表达式的运算结果,设 a=2,b=-4,c=true。 (1) - - a % b+ +

(2) ( a >= 1 && a <= 10? a : b) (3) c ^( a > b) (4) (- - a )<

(5) (double)(a+b)/5+a/b 答案为:


第一章 JAVA基础(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:中国日用搪瓷用冷轧薄钢板行业市场调研及未来五年盈利前景预测报

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: