Q2. in Each of the Following Statements What Is the Value of the Variable I ?

Total Page:16

File Type:pdf, Size:1020Kb

Q2. in Each of the Following Statements What Is the Value of the Variable I ?

Kingdom of Saudi Arabia Ministry of Higher Education Al-Maarefa College for Science and Technology Faculty of Computer Science and Information Systems

(Tutorial (1

:Q1. For the following, mark illegal Identifiers and describe why they are illegal

Description Legal / illegal Identifier # Student .1

1stBook .2

Book1 .3

School fees .4

Class .5

My_Book .6

SchoolFeesAfterDiscount .7

? Q2. In each of the following statements what is the value of the variable I

;I = 4+2*3 .1

;I = 3 / 2 + 5.0 .2

;(I = 9 / (2+1 .3

;I = (4*6/2+8) % 2 .4

;I = 10/2 – 5 % 3 *4 .5

;I = 15.6 / 2 + 5 .6

;I = 4 * 3 + 7 / 5 - 25.5 .7 ;I = (int) 4.6 + 3/2 .8

;(I = (int) (4.6 + 3/2 .9

.Q3. Write a java code that prints your name

.Q4. Trace the following java codes then write the output 1 } public class salary

(public static void main (String [] args } ;final int WEEK_DAYS =7

;double SalaryPerHour =100, WeeklySalary, deduction

;int WorkingHours =8

;deduction= SalaryPerHour*3

;deduction+=40

WeeklySalary = SalaryPerHour * WorkingHours * WEEK_DAYS - ;deduction

System.out.println("employee salary is "+SalaryPerHour+" * ;( "+WorkingHours+" * "+WEEK_DAYS+" - "+deduction+" = "+WeeklySalary

{ { 2 } public class FahrenheitToCelsius

} (public static void main(String[] args

;double celsius, fahrenheit

;fahrenheit = 10.00

;celsius = (fahrenheit-32)*5/9

System.out.println("The amount of Fahrenheit is equal to \n \"" + celsius ;(" "\.+ " degrees Celsius { { :Q5.Write a program that prints the following banner

AAA VV VV AAA JJJJJJJJJJJJ AA AA VV VV AA AA JJ AA AA VV VV AA AA JJ AAAAAAAAA VV VV AAAAAAAA JJ AA AA VV VV AA AA JJ JJ AA AA VVV AA AA JJJJJJ

. Q6. Write a program that calculates the average of two integers then print the result

: Q7. Find the error in the following codes 1

public class ProgWithErrorsA } ;static final int SECRET_NUM = 11,213 ;static final double 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 { {

2

public class ProgWithErrorsA } '*' = static final char = STAR ;static final int PRIME = 71 (public static void main(String[] arg } ;count = 1 ;sum = count + PRIME ;x := 25.67 ;newNum = count * ONE + 2 ;sum + count = sum ;x = x + sum * COUNT " = System.out.println(" count = " + count + ", sum ;(sum + ", PRIME = " + Prime + { {

Recommended publications