Java Fundamentals Week test questions with answers

Source: Internet
Author: User
Tags bitwise byte sizes

    1. Simple question (5 points per question, total 50 points)
    1. Brief introduction to the principle of the Java language cross-platform

The Java cross-platform feature, that is, the same byte-code file can be executed on different systems,

The Java virtual machines in different systems are responsible for translating the corresponding machine instructions.

    1. Write the concepts and respective roles of the following nouns

Jre-java Run-time environment information, as long as the application running Java writing needs to be installed.

The Jdk-java SDK, as long as the Java application is written, needs to be installed, and the toolkit contains the JRE.

Jvm-java the virtual machine, interprets the bytecode file as a machine instruction.

Javac.exe-java compiler for converting advanced source code files to bytecode files.

The Java.exe-java explains the executor, which is used to interpret and execute bytecode files through a Java virtual machine.

    1. Brief introduction of basic concepts and definitions of variables in Java

A variable is a storage area that is requested in memory to store various types of data. Depending on the size of the data stored, there are variables of different data types. The specific form is:

Data type variable name = initial value; -where = initial value can be omitted, semicolon can not be omitted.

    1. Main categories of variables

By the data type that belongs to:

Basic Data type variables

Reference data type variables

Divided by the declared location:

Local variables: Variables defined inside a method or statement block

Member variables: Variables that are internally defined by methods outside of the class

    1. Naming rules for identifiers

(1) consisting of letters, numbers, underscores and US $ $, numbers cannot begin.

(2) The identifier length is not explicitly qualified, but not too long.

(3) cannot have the same name as a keyword in Java, such as: public class int ...

(4) Case-sensitive.

(5) It can be Chinese characters, but it is not recommended.

    1. Brief description of all the basic data types in the Java language and the size of each data type occupying memory space

The data types that describe integers are mainly: Byte/short/int/long, which occupy 1/2/4/8 byte sizes.

The data types that describe decimals are: float/double, which occupy 4/8 byte sizes, respectively.

The data types that describe true and false are: Boolean, which takes up to 1 bytes in size.

The data type of the description character is: Char, which occupies 2 bytes.

    1. A brief description of the conversion method between binary and decimal, decimal and binary

(1) Non-negative decimal conversion to binary

In addition to the 2 fetch method, the decimal integer is continuously divided by 2 to remove the remainder, and all binary digits are reversed when quotient is 0.

Split method: That is, the decimal integer is split into a number of 2 of the Sub-party composition.

(2) Non-negative binary conversion to decimal

using the weighted method, that is, each number and the current weight multiplied, and then added up.

(3) Negative binary conversion to decimal

Each digit in the binary is reversed by a bitwise, plus 1, converted to decimal and then added minus.

(4) Negative decimal conversion to binary

splits the absolute value of a decimal integer into binary, then the bitwise inverse, and the last 1.

    1. Please write out the three syntax formats of the IF statement

(1) if (conditional expression) {statement block;}

(2) if (conditional expression) {statement block 1;}

else {statement block 2;}

(3) if (conditional expression 1) {statement block 1;}

else if (conditional expression 2) {statement block 2;}

... ...

else {statement block 3;}

    1. Please write out how the declaration defines the array (at least two types)

element type [] Variable name = new element type [number of elements];

element type [] Variable name = {element 1, element 2 ...} ;

element type [] Variable name = new element type []{element 1, element 2 ...}

    1. Describes the range of values represented by a single byte and writes out the derivation process.

The non-negative representation range is: 0000 0000 ~ 0111 1111 = 0 ~ 127 = 0 ~ 2^7-1

0111 1111 = + + + + 8 + 4 + 2 + 1 = 127

The range of negative numbers is: 0000 ~ 1111 1111 = -128 ~ 1 = -2^7 ~ -2^0

0000 = 0111 1111 = 0000 = 128

1111 1111 = 0000 0000 = 0000 0001 = 1 = 1

Sum up:

The range of decimal integers that can be represented by 1 bytes is:-128 ~ 127, which is -2^7 ~ 2^7-1.

    1. Programming questions (10 points per question, 50 points total)
    1. Use the If-else IF-ELSE branch structure to determine the level of the user's input and print out the score.

[90 ~ 100] Print Class A

[80 ~ 89] Print Class B

[70 ~ 79] Print level C

[60 ~ 69] Print Grade D

[0 ~ 59] Print Level E

Import Java.util.Scanner;

public class Text {

public static void Main (string[] args) {

Scanner sc = new Scanner (system.in);

SYSTEM.OUT.PRINTLN ("Please input query score:");

int aa = Sc.nextint ();

if (AA >= && aa<=100) {

System.out.println ("A");

}

if (aa>=80&&aa<=89) {

System.out.println ("B");

}

if (aa>=70&&aa<=79) {

System.out.println ("C");

}

if (aa>=60&&aa<=69) {

System.out.println ("D");

}

if (aa>=0&&aa<=59) {

System.out.println ("E");

}

}

}

    1. prompts the user to enter a positive integer and output in reverse order.

Import Java.util.Scanner;

public class Text {

public static void Main (string[] args) {

Scanner sc = new Scanner (system.in);

System.out.println ("Please enter an integer:");

int bb = Sc.nextint ();

int num=0;

while (bb!=0) {

num = bb%10+num*10;

bb = BB/10;

}

SYSTEM.OUT.PRINTLN ("Reverse output:" +num);

}

3. programming to achieve 1-100 random number generation, give the user 10 times to enter the opportunity to guess the generated number, if the input number equals random number to print "Congratulations you guessed right", and end the loop; If the input number is less than the random number, print "Too small, a little larger." If the input number is greater than the random number, print "Too big, a little bit smaller"; If you run out of 10 chances, print "Too stupid, come again next time".

Import Java.util.Random;

Import Java.util.Scanner;

public class Text {

public static void Main (string[] args) {

int number = (int) (Math.random () *100);

Scanner sc = new Scanner (system.in);

int a=0;

do {

a++;

if (a>10) {

System.out.println ("Too stupid, come again next time");

Break

}

System.out.println ("Please enter an integer within 100:");

int bb = Sc.nextint ();

if (Bb<number) {

System.out.println ("Too small, a little bigger");

}else if (bb>number) {

System.out.println ("Too big, a little bit smaller");

}else{

System.out.println ("Congratulations on your guess right");

Break

}

System.out.println ("remaining" + (10-A) + "Second Chance");

}while (true);

}

}

  4. use a double loop to print all the primes between the 2~200.

public class Text {

public static void Main (string[] args) {

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

Boolean A = true;

for (int j = 3; J < I; J + +) {

if (i%j==0) {

A = false;

Break

}

}

if (a) {

System.out.println (i);

}

}

}

}  

    1. An int array is known to arr = {12,4,22,11,24,9}, finding the maximum and minimum values and printing.

public class Text {

Public static void Main (string[] args) {

int []arr ={12,4,22,11,24,9};

int min = 0;

int max = 0;

MIN=MAX=ARR[0];

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

if (Arr[i]>max)

Max=arr[i];

if (arr[i]<min)

Min=arr[i];

}

System.out.println ("The maximum value of the array is:" +max);

System.out.println ("The minimum value of the array is:" +min);

}

}

Java Fundamentals Week test questions with answers

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.