-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch_79_error_eg.java
37 lines (32 loc) · 1.07 KB
/
ch_79_error_eg.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.Scanner;
public class ch_79_error_eg {
public static void main(String[] args) {
// SYNTAX ERROR DEMO
// int a = 0 // Error: no semicolon!
// b = 8; // Error: b not declared!
// LOGICAL ERROR DEMO
// Write a program to print all prime numbers between 1 to 10
System.out.println(2);
for (int i = 1; i < 5; i++) {
System.out.println(2 * i + 1);
}
// 9 gets printed which is not a prime error
// RUNTIME ERROR
int k;
Scanner sc = new Scanner(System.in);
k = sc.nextInt();
System.out.println("Integer part of 1000 divided by k is " + 1000 / k);
sc.close();
}
}
/*
* syntax errors are those errors which are found in the program and are found
* while compiling the program.
*
* logical errors are those error when a developer doesnt get the desired output
* from the program even when the program has no errors.
*
* runtime error occurs due to some exceptional test cases which makes the
* program fail during the runtime
*
*/