Mid-Term Syllabus
Chapter 1: Operating System and GUI – Role and Functions
Chapter 2: Spreadsheet – Formulas and Functions
Chapter 3: Charts in Excel 2016
Chapter 5: Introduction to Program Coding – Java and BlueJ
Final-Term Syllabus
Chapter 4: Algorithms and Flowcharts
Chapter 8: Networks
Chapter 9: Cloud Computing
Chapter 13: Domains of Artificial Intelligence
Sample Java Programs for Class 8 Students
- Write a Java program to input two integers and swap them using a temporary variable. Display the new values of the variables.
import java.util.Scanner;
class Swap{
public static void main(String args[]){
System.out.print("First integer: ");
int a = Integer.parseInt(in.nextLine());
System.out.print("Second integer: ");
int b = Integer.parseInt(in.nextLine());
int temp = a;
a = b;
b = temp;
System.out.println("First number = " + a);
System.out.println("First number = " + a);
}
} - Write a Java program to input the radius of a circle and find and display its area and circumference.
import java.util.Scanner;
class Circle{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("Radius of the circle: ");
double r = Double.parseDouble(in.nextLine());
double a = Math.PI * r * r;
double c = 2 * Math.PI * r;
System.out.println("Area: " + a);
System.out.println("Circumference: " + c);
}
}
3. Write a Java program to input the year and check and display whether it is a leap year or not.
import java.util.Scanner;
class Leap{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("Year: ");
int y = in.nextInt();
if(y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))
System.out.println(y + " is a leap year!");
else
System.out.println(y + " is not a leap year.");
}
}