You are on page 1of 4

COMSATS UNIVERSITY ISLAMABAD

PROGRAMMING FUNDAMENTALS

ASSIGNMENT # 01

AMAAN AHMAD
18-10-2022
AMAAN AHMAD SP22-BCT-004 CYBER SECURITY
2ND SEMESTER PROGRAMMING FUNDAMENTALS

ASSIGNMENT # 01

PROGRAMMING FUNDAMENTALS

Question # 01:

a. Write JAVA statements that can produce Syntax Errors. Give three different examples and
write the names of the errors
Answer (a): Syntax errors are those errors that prevent the code from running because of
an incorrect syntax such as a missing semicolon at the end of a statement or a missing
bracket, class not found, etc. These errors are detected by the java compiler and an error
message is displayed on the screen while compiling.

Missing Semi-Colon (;)

Misspelled variable name or


method names

Missing Parenthesis or Bracket ) b.

Write JAVA statements that can produce Logical Errors. Give three different examples
and briefly explain the reason (1-2 lines)
c. Write JAVA statements that can produce Run Time Errors. Give three different examples and
briefly explain the reason (1-2 lines)
AMAAN AHMAD SP22-BCT-004 CYBER SECURITY
2ND SEMESTER PROGRAMMING FUNDAMENTALS

Answer: Run Time errors occur or are detected during the execution of the program.
Sometimes these are discovered when the user enters invalid data or data which is not
relevant. Runtime errors occur when a program does not contain any syntax errors but
asks the computer to do something that the computer is unable to reliably do or
something which logically, or mathematically is not correct. For example,

d. The following program has syntax errors. Write clearly the type of error and its correction (in
tabular form). After you have corrected the syntax errors, show the output of this program.

public class Test{


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);
}
}
AMAAN AHMAD SP22-BCT-004 CYBER SECURITY
2ND SEMESTER PROGRAMMING FUNDAMENTALS

You might also like