0% found this document useful (0 votes)
10 views2 pages

Java Assignment

This document outlines an assignment for the Programming Fundamentals course, focusing on types of errors in Java. It provides examples of syntax errors, logical errors, and runtime errors, along with explanations for each. The assignment is due on March 14, 2025, and is worth a total of 25 marks.

Uploaded by

malikumarali45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Java Assignment

This document outlines an assignment for the Programming Fundamentals course, focusing on types of errors in Java. It provides examples of syntax errors, logical errors, and runtime errors, along with explanations for each. The assignment is due on March 14, 2025, and is worth a total of 25 marks.

Uploaded by

malikumarali45
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Theory Assignment - 1

Course: Programming Fundamentals (CSC103)

Instructor: Haseeb Ur Rehman

Total Marks: 25

Submission Date: 14th March 2025

Question 1: Types of Errors


a. Java Statements Producing Syntax Errors:

// Example 1: Missing Semicolon


int x = 10
// Error: ';' expected

// Example 2: Incorrect Variable Declaration


int 2number = 5;
// Error: Identifier cannot start with a digit

// Example 3: Mismatched Brackets


public class Example {
public static void main(String[] args) {
System.out.println("Hello World!";
}
}

b. Java Statements Producing Logical Errors:

// Incorrect Formula for Average


int a = 10, b = 20, avg;
avg = a + b / 2; // Incorrect precedence

// Using Wrong Comparison Operator


int x = 5;
if (x = 10) { // Should be '==' instead of '='
System.out.println("x is 10");
}

// Wrong Loop Condition


for (int i = 0; i > 10; i++) { // Should be i < 10
System.out.println(i);
}

c. Java Statements Producing Runtime Errors:


// Division by Zero
int a = 10, b = 0;
System.out.println(a / b); // Throws ArithmeticException

// Accessing Out of Bounds Index


int[] arr = {1, 2, 3};
System.out.println(arr[5]); // Throws ArrayIndexOutOfBoundsException

You might also like