Sie sind auf Seite 1von 4

1. What does it print?

public class LongDivision { private static final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000; private static final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000; public static void main(String[] args) { System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY); } } (a) (b) (c) (d) 5 1000 5000 Throws an exception

2.What does it print? public class Rhymes { private static Random rnd = new Random(); public static void main(String[] args) { StringBuffer word = null; switch(rnd.nextInt(2)) { case 1: word = new StringBuffer('P'); case 2: word = new StringBuffer('G'); default: word = new StringBuffer('M'); } word.append('a'); word.append('i'); word.append('n'); System.out.println(word); } } (a) (b) (c) (d) Pain, Gain, or Main (varies at random) Pain or Main (varies at random) Main (always) None of the above

3.What does it print? public class NameGame { public static void main(String args[]) { Map m = new IdentityHashMap(); m.put("Mickey", "Mouse"); m.put("Mickey", "Mantle"); System.out.println(m.size()); } } (a) (b) (c) (d) 0 1 2 It varies

4.What does it print?

public class Names { private Map m = new HashMap(); public void Names() { m.put("Mickey", "Mouse"); m.put("Mickey", "Mantle"); } public int size() { return m.size(); } public static void main(String args[]) { Names names = new Names(); System.out.println(names.size()); } } (a) (b) (c) (d) 0 1 2 It varies

5.What does it print? public class Gray { public static void main(String[] args){ System.out.println(X.Y.Z); } } class X { static class Y { static String Z = "Black"; } static C Y = new C(); } class C { String Z = "White"; } (a) (b) (c) (d) Black White Won t compile None of the above

6.What does it print? public class Elementary { public static void main(String[] args) { System.out.println(54321 + 5432l); } } (a) (b) (c) (d) -22430 59753 10864 108642

7.What does it print?

public class Count { public static void main(String[] args) { final int START = 2000000000; int count = 0; for (float f = START; f < START + 50; f++) count++; System.out.println(count); } } (a) (b) (c) (d) 0 50 51 None of the above

8.What does it print? public class LinePrinter { public static void main(String[] args) { // Note: \u000A is Unicode representation for newline char c = 0x000A; System.out.println(c); } } (a) (b) (c) (d) Two blank lines 10 Won t compile It varies

9.Find the missing values (denoted by #) Output: c0 ef f1 import java.io.*; class Q2 { public static void main(String []arg) { byte a= #>>1,b= #>>1,c,d,e; c=(byte)(a&b); d=(byte)(a|b); e=(byte)(b+2); System.out.println(Integer.toString((c&0xff)+0x100,16).substring(1)); //convert byte into hex System.out.println(Integer.toString((d&0xff)+0x100,16).substring(1)); //convert byte into hex System.out.println(Integer.toString((e&0xff)+0x100,16).substring(1)); //convert byte into hex } } 10.consider a computer in a network which receives packet at regular intervals.The format of the packet is Header Message Flag

Header : 4 bytes message: n bytes where n is the no. of ones in header(no. of ones in the binary representation) Flag : 1 bytes Since the message length depends on header info,it can't be retrieved unless the no. of ones in header is found. XYZ wrote a program to find it out: import java.io.*; class q3 {p ublic static int RetrieveHeader(String pack) {. ..//remove higher order 4 bytes from pack and convert into decimal value ....//return decimal value } public static void main(String []arg) { BufferedReader packet=new BufferedReader(new InputStreamReader(System.in)); int a=RetrieveHeader(packet.readLine()); int len=0; while((a&0xffffffff)!=0) { len+=a&0x00000001; a=a>>1; }}} what could be the max length of the message(in bytes) for the program to work correctly?find the hexadecimal equivalent of the header in that case.

Das könnte Ihnen auch gefallen