Question

In: Computer Science

Advance programing in java Qn1 1.True or False: (a) A sequence of 0s and 1s is...

Advance programing in java

Qn1

1.True or False:
(a) A sequence of 0s and 1s is called a decimal code.
(b) ZB stands for zero byte.
(c) The CPU stands for command performing unit.
(d) Every Java application program has a method called main.
(e) An identier can be any sequence of digits and letters.
(f) Every line in a program must end with a semicolon.
2. Explain the two most important benets of the Java language
3 Explain the dierences between machine languages and high-level languages?
4 Explain the dierence between a keyword and a user-dened identier?
5 Are the identiers rstName and FirstName the same?


Qn2 Which of the following are valid Java identiers?
(a) myFirstProgram (b) MIX-UP (c) JavaProgram2
(d) quiz7 (e) ProgrammingLecture2 (f) 1footEquals12Inches
(g) Mike'sFirstAttempt (h) Update Grade (i) 4th
(j) New Student


Qn3 The following program has syntax errors. Correct them. On each
successive line, assume that any preceding error has been corrected. After you have
corrected the syntax errors, type and compile the program to check if all errors have
been found.
public class Qn3
{
static final int SECRET_NUM = 11 ,213;
static final PAY_RATE = 18.35
public void main ( String [] arg)
{
int one , two;
double first , second
one = 18;
two = 11;
first = 25;
second = first * three ;
second = 2 * SECRET_NUM ;
SECRET_NUM = SECRET_NUM + 3
System .out. println ( first + " " + second + " "
+ SECRET_NUM );
paycheck = hoursWorked * PAY_RATE
System .out. println (" Wages = " paycheck );
}
}


Qn 4 )Write a program that prompts the user to input ve decimal numbers.
The program should then add the ve decimal numbers, convert the sum to the
nearest integer, and print the result.
Screen shot of the output:

Solutions

Expert Solution

1.True or False:
(a) A sequence of 0s and 1s is called a decimal code. : FALSE . BINARY CODE
(b) ZB stands for zero byte. FALSE , ZETTA BYTE
(c) The CPU stands for command performing unit. FALSE , CENTRAL PROCESSING UNIT
(d) Every Java application program has a method called main. TRUE, MAIN IS STARTING POINT OF EXECUTION
(e) An identier can be any sequence of digits and letters. FALSE, FIRST CHARACTER SHOULD BE UNDERSCORE OR ALPHABET
(f) Every line in a program must end with a semicolon. TRUE

2. Explain the two most important benets of the Java language

ANS:

I)Java is platform-independent.

The ability to run the same program on many different systems is crucial to World Wide Web software, and Java succeeds at this by being platform-independent at both the source and binary levels.

II) Java is object-oriented.

This allows you to create modular programs and reusable code.

3 Explain the dierences between machine languages and high-level languages?

1.

high-level languages

It is programmer friendly language.

machine languages a

It is a machine friendly language.

3. High level language is less memory efficient. Low level language is high memory efficient.
4. It is easy to understand. It is tough to understand.
5. It is simple to debug. It is complex to debug comparatively.

4. Explain the dierence between a keyword and a user-dened identier?

Keywords are predefined reserved words, which possess special meaning. Each keyword defines the “type” declared data. Keywords should not be used as identifiers.EX int char double

An identifier is a unique name given to a particular variable, function or label of class in the program. To create a variable, both a keyword and an identifier are bind together. ex int num

5 Are the identifiers rstName and FirstName the same?

No Java is Case sensitive. there are not the same for java

Qn2 Which of the following are valid Java identiers?
(a) myFirstProgram (b) MIX-UP (c) JavaProgram2
(d) quiz7 (e) ProgrammingLecture2 (f) 1footEquals12Inches
(g) Mike'sFirstAttempt (h) Update Grade (i) 4th
(j) New Student

valid: a,c,d,e,i

invalid: b,f,g,h,j

Rules:

  • Each identifier must have at least one character.
  • The first character must be picked from: alpha, underscore, or dollar sign. The first character can not be a digit.
  • The rest of the characters (besides the first) can be from: alpha, digit, underscore, or dollar sign. In other words, it can be any valid identifier character.

Qn3 The following program has syntax errors. Correct them. On each
successive line, assume that any preceding error has been corrected. After you have
corrected the syntax errors, type and compile the program to check if all errors have
been found.
public class Qn3
{
static final int SECRET_NUM = 11 ,213;
static final PAY_RATE = 18.35
public void main ( String [] arg)
{
int one , two;
double first , second
one = 18;
two = 11;
first = 25;
second = first * three ;
second = 2 * SECRET_NUM ;
SECRET_NUM = SECRET_NUM + 3
System .out. println ( first + " " + second + " "
+ SECRET_NUM );
paycheck = hoursWorked * PAY_RATE
System .out. println (" Wages = " paycheck );
}
}

Ans:

/* CORRECTION AND ASSUMING RANDOM VALUE TO NOT INITIATED VARIABLE */

public class Qn3
{
static int SECRET_NUM = 11;
static final int three = 213;
static final double PAY_RATE = 18.35;
public static void main ( String [] arg)
{
int one , two,hoursWorked = 2;
double first , second;
one = 18;
two = 11;
first = 25;
second = first * three ;
second = 2 * SECRET_NUM ;
SECRET_NUM = SECRET_NUM + 3;
System .out. println ( first + " " + second + " "
+ SECRET_NUM );
double paycheck = hoursWorked * PAY_RATE;
System .out. println (" Wages = " +paycheck );
}
}

/* OUTPUT */

run:
25.0 22.0 14
Wages = 36.7

Qn 4 )Write a program that prompts the user to input ve decimal numbers.
The program should then add the ve decimal numbers, convert the sum to the
nearest integer, and print the result.
Screen shot of the output:

#include <iostream>
using namespace std;

double a, b , c , d , e, f;

int main(int argc, char* argv[])
{
cout << "enter 5 decimals: " << endl;
cin >> a >> b >> c >> d >> e;
f = a + b + c + d + e;
cout << static_cast<int> (f + .5)<< endl;
return 0;
}


Related Solutions

The transmitter transmits either an infinite sequence of 0s with a probability 2/3 or 1s with...
The transmitter transmits either an infinite sequence of 0s with a probability 2/3 or 1s with a probability 1/3. Each symbol, regardless of the others and the transmitted sequence is identified by the receiving device with an error with a probability 0.25. i) Given that the first 5 identified symbols are 0s, find the probability P (000000 | 00000) that the sixth received symbol is also zero. b) Find the average value of a random variable equal to the number...
A string of 0s and 1s is to be processed and converted to an even-parity string...
A string of 0s and 1s is to be processed and converted to an even-parity string by adding a parity bit to the end of the string.(For an explanation of the use of parity bits, see Example 30 in Chapter 9.) The parity bit is initially 0. When a 0 character is processed, the parity bit remains unchanged. When a 1 character is processed, the parity bit is switched from 0 to 1 or from 1 to 0. Prove that...
P [1r / 0s] = 0.03 and P [0r / 1s] = 0.02 conditional in an...
P [1r / 0s] = 0.03 and P [0r / 1s] = 0.02 conditional in an asymmetric binary communication channel available. The probability of sending 0 in this channel is P [1s] = 0.56. 25 bits from this channel It has been sent. Accordingly, find the possibility of fewer than 3 faulty bits in the 25 bits transmitted. Note: 0s : 0 transmit, 1s : 1 transmit, 0r : 0 represent, 1r : 1 represent running events.
true or false and explain. thanks in advance. 1. According to the dividend discount model, the...
true or false and explain. thanks in advance. 1. According to the dividend discount model, the value an investor assigns to a share of stock is dependent upon the length of time the investor plans to hold the stock. 2. If the yield to maturity of a bond is greater then It's coupon rate, the market value of the bond will always be below its par value. 3. the weighted average cost of capital reflects the average cost of the...
(C++) Write a program that randomly fills in 0s and 1s into a 5-by-5 matrix,prints the...
(C++) Write a program that randomly fills in 0s and 1s into a 5-by-5 matrix,prints the matrix,and finds which row and column with more 1s and display that row and column number.            
A population contains nine million 0s and seven million 1s. What is the sampling distribution of...
A population contains nine million 0s and seven million 1s. What is the sampling distribution of the sample mean when the sample size is n=5? Let X be the number of 1s. Complete the chart below. X ​P(X) x 0 nothing nothing 1 nothing nothing 2 nothing nothing 3 nothing nothing 4 nothing nothing 5 nothing nothing ​(Round to three decimal places as​ needed.)
is it true or false; Any deletion mutation in the coding sequence of a proton will...
is it true or false; Any deletion mutation in the coding sequence of a proton will result in a protein sequence change
Which statements are true for an electron in the 1s orbital of hydrogen ? 1. The...
Which statements are true for an electron in the 1s orbital of hydrogen ? 1. The potential energy of the electron is negative. 2. The total energy of the electron is constant. 3. The kinetic energy of the electron is positive.
48 sample - 9 "0s" = 39 39 "1s" / 48 total sample= 0.8125 pq=0.9*(1-0.9) 0.09...
48 sample - 9 "0s" = 39 39 "1s" / 48 total sample= 0.8125 pq=0.9*(1-0.9) 0.09 pq/n= 0.09/48 0.001875 sqrt (pq/n)= sqrt (0.001875) 0.043301 sample prop / 90% =0.8125-0.9 -0.0875 z=-0.0875/0.043301 -2.02073 p value =NORMSDIST(H7) 0.02165 An air quality instrument logs 0 when standards are not met and 1 when standards are met. The log is saved to file DATA. First, compute the proportion meeting standards as the mean of air quality values. Second, at alpha=0.10 (sensitive, exploratory), test the...
48 sample - 9 "0s" = 39 39 "1s" / 48 total sample= 0.8125 pq=0.9*(1-0.9) 0.09...
48 sample - 9 "0s" = 39 39 "1s" / 48 total sample= 0.8125 pq=0.9*(1-0.9) 0.09 pq/n= 0.09/48 0.001875 sqrt (pq/n)= sqrt (0.001875) 0.043301 sample prop / 90% =0.8125-0.9 -0.0875 z=-0.0875/0.043301 -2.02073 p value =NORMSDIST(H7) 0.02165 An air quality instrument logs 0 when standards are not met and 1 when standards are met. The log is saved to file DATA. First, compute the proportion meeting standards as the mean of air quality values. Second, at alpha=0.10 (sensitive, exploratory), test the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT