0% found this document useful (0 votes)
7 views26 pages

Executed Programs in Java - Chapter 1 and 6

The document is a project titled 'Executed Programs in Java – Chapter 1 and 6' by Yashraj Shekhar, which includes a compilation of core Java programs aligned with the ICSE Class X syllabus. It features various programs covering fundamental Java concepts such as input/output, data types, and control structures, each accompanied by problem statements, code, variable descriptions, and output examples. The project aims to enhance coding skills and demonstrate the application of structured logic in solving real-world problems.

Uploaded by

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

Executed Programs in Java - Chapter 1 and 6

The document is a project titled 'Executed Programs in Java – Chapter 1 and 6' by Yashraj Shekhar, which includes a compilation of core Java programs aligned with the ICSE Class X syllabus. It features various programs covering fundamental Java concepts such as input/output, data types, and control structures, each accompanied by problem statements, code, variable descriptions, and output examples. The project aims to enhance coding skills and demonstrate the application of structured logic in solving real-world problems.

Uploaded by

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

Executed Programs in Java –

Chapter 1 and 6

Name: Yashraj Shekhar


Class: X
Roll No: 10A030
School: St. Thomas
Internal Examiner: ____________
External Examiner: ____________
ACKNOWLEDGEMENT
I would like to express my special thanks of gratitude to my teacher Mrs.
Divya Ma'am and as well as our Principal Madam who gave me the
golden opportunity to do this wonderful project. This project also helped
me in doing a lot of research and I came to know about so many new
things.

I am extremely grateful to my parents who gave me valuable guidance


and suggestions for the completion of my project.
INDEX
S.No​ Date​ Title of Program​ Page No. Sign

1 3rd June Introduction 4


2​ 3rd June​ Program to display “Hello World”​ 5
3​ 3rd June​ Sum of Two Numbers​​ 6
4​ 3rd June​ Area of a Rectangle​ ​ 7
5​ 4th June​ Perimeter of a Square​​ 8
6​ 4th June​ Simple Interest Calculation​ ​ 9
7​ 4th June​ Average of Three Numbers​ 10
8 5th June Convert Celsius to Fahrenheit​ 11
9​ 5th June​ Check Even or Odd​ ​ 12
10​ 5th June​ Find Greatest of Two Numbers​ 13
11​ 5th June​ Swapping Two Numbers​ ​ 14
12​ 6th June​ Use of if-else: Grade Checker​ 15​
13​ 6th June​ Use of switch-case: Calculator​ 16
14​ 6th June​ While Loop: Sum of first 10 numbers 17​ ​
15​ 6th June​ For Loop: Factorial of a Number​ 18​
16​ 7th June​ Nested if: Check Leap Year​ ​ 19
17​ 7th June​ Do-while Loop: Table of a Number​ 20
18​ 7th June​ Accept String and Display​ ​ 21
19​ 7th June​ Length of a String​ ​ 22
20​ 7th June​ Accept Character and Display ASCII 23​ ​
21​ 7th June​ Use of Math Functions​ 24
22 7th June Conclusion​ 25
23 7th June Bibliography 26
PROJECT INTRODUCTION
This project titled "Executed Programs in Java – Chapter 1 and 6" is a
practical compilation of core Java programs as outlined in the syllabus of
ICSE Class X Computer Applications, based on the textbook
Understanding Computer Applications with BlueJ by Avichal Publishing.

The programs included are selected from Chapter 1 (Revision of Class


IX) and Chapter 6 (Decision Making and Looping). These topics form the
foundation of basic Java programming. Each program is complete with
a:

Problem Statement

Java Code

Variable Description Table (VDT)

Output Example

The aim of this project is to demonstrate practical understanding of Java


concepts like input/output, data types, operators, conditional statements,
loops, and use of classes and objects. It not only strengthens my coding
skills but also provides insight into how structured logic solves real-world
problems using programming.
PROGRAMS
Program 1: Hello World

Problem: Display "Hello, World!"

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

VDT:

Variable​ Data Type​ Description

args​ String[]​ Command-line argument

Output: Hello, World!


Program 2: Sum of Two Numbers

Problem: Accept two integers and print their sum.

import java.util.Scanner;
class Sum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, b, sum;
System.out.print("Enter first number: ");
a = sc.nextInt();
System.out.print("Enter second number: ");
b = sc.nextInt();
sum = a + b;
System.out.println("Sum = " + sum);
}
}

VDT:

Variable​ Data Type​ Description

a​ int​ First number


b​ int​ Second number
sum​ int​ Result (a + b)

Output: Enter first number: 4


Enter second number: 6
Sum = 10
Program 3: Area of a Rectangle

Problem: Calculate the area of a rectangle using length and breadth.

import java.util.Scanner;
class RectangleArea {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int length, breadth, area;
System.out.print("Enter length: ");
length = sc.nextInt();
System.out.print("Enter breadth: ");
breadth = sc.nextInt();
area = length * breadth;
System.out.println("Area = " + area);
}
}

VDT:

Variable​ Data Type​ Description

length​int​ Length of rectangle


breadth​ int​ Breadth of rectangle
area​ int​ Area of rectangle

Output: Enter length: 5


Enter breadth: 4
Area = 20
Program 4: Perimeter of a Square

Problem: Calculate the perimeter of a square.

import java.util.Scanner;
class SquarePerimeter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int side, perimeter;
System.out.print("Enter side: ");
side = sc.nextInt();
perimeter = 4 * side;
System.out.println("Perimeter = " + perimeter);
}
}

VDT:

Variable​ Data Type​ Description

side​ int​ Side of the square


perimeter​ int​ Perimeter of square

Output: Enter side: 6


Perimeter = 24
Program 5: Simple Interest Calculation

Problem: Calculate simple interest.

import java.util.Scanner;
class SimpleInterest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double p, r, t, si;
System.out.print("Enter Principal: ");
p = sc.nextDouble();
System.out.print("Enter Rate: ");
r = sc.nextDouble();
System.out.print("Enter Time: ");
t = sc.nextDouble();
si = (p * r * t) / 100;
System.out.println("Simple Interest = " + si);
}
}

VDT:

Variable​ Data Type​ Description

p​ double​ Principal
r​ double​ Rate of Interest
t​ double​ Time
si​ double​ Simple Interest result

Output: Enter Principal: 1000


Enter Rate: 5
Enter Time: 2
Simple Interest = 100.0
Program 6: Average of Three Numbers

Problem: Find the average of three numbers entered by the user.

import java.util.Scanner;
class Average {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, b, c;
double avg;
System.out.print("Enter first number: ");
a = sc.nextInt();
System.out.print("Enter second number: ");
b = sc.nextInt();
System.out.print("Enter third number: ");
c = sc.nextInt();
avg = (a + b + c) / 3.0;
System.out.println("Average = " + avg);
}
}

VDT:

Variable​ Data Type​ Description

a, b, c​ int​ Three numbers entered by the user


avg​ double​ Average of the numbers

Output: Enter first number: 5


Enter second number: 7
Enter third number: 9
Average = 7.0
Program 7: Convert Celsius to Fahrenheit

Problem: Convert a temperature from Celsius to Fahrenheit.

import java.util.Scanner;
class TempConverter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double celsius, fahrenheit;
System.out.print("Enter temperature in Celsius: ");
celsius = sc.nextDouble();
fahrenheit = (celsius * 9/5) + 32;
System.out.println("Temperature in Fahrenheit = " + fahrenheit);
}
}

VDT:

Variable​ Data Type​ Description

celsius​ double​ Temperature in Celsius


fahrenheit​ double​ Converted temperature in Fahrenheit

Output: Enter temperature in Celsius: 25


Temperature in Fahrenheit = 77.0
Program 8: Check Even or Odd

Problem: Check whether a number is even or odd.

import java.util.Scanner;
class EvenOdd {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num;
System.out.print("Enter a number: ");
num = sc.nextInt();
if(num % 2 == 0)
System.out.println("Even number");
else
System.out.println("Odd number");
}
}

VDT:

Variable​ Data Type​ Description

num​ int​ Number to be checked

Output: Enter a number: 4


Even number
Program 9: Find Greatest of Two Numbers

Problem: Determine the greatest of two numbers.

import java.util.Scanner;
class Greatest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, b;
System.out.print("Enter first number: ");
a = sc.nextInt();
System.out.print("Enter second number: ");
b = sc.nextInt();
if(a > b)
System.out.println(a + " is greater");
else if (a < b)
System.out.println(b + " is greater");
else
System.out.println("Both are equal");
}
}

VDT:

Variable​ Data Type​ Description

a, b​ int​ Input numbers

Output: Enter first number: 10


Enter second number: 20
20 is greater
Program 10: Swapping Two Numbers

Problem: Swap values of two variables using a temporary variable.

import java.util.Scanner;
class Swap {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, b, temp;
System.out.print("Enter value of a: ");
a = sc.nextInt();
System.out.print("Enter value of b: ");
b = sc.nextInt();
temp = a;
a = b;
b = temp;
System.out.println("After swapping: a = " + a + ", b = " + b);
}
}

VDT:

Variable​ Data Type​ Description

a, b​ int​ Values to be swapped


temp​ int​ Temporary storage

Output: Enter value of a: 5


Enter value of b: 10
After swapping: a = 10, b = 5
Program 11: Use of if-else – Grade Checker

Problem: Accept marks and display grade using if-else.

import java.util.Scanner;
class GradeChecker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int marks;
System.out.print("Enter marks: ");
marks = sc.nextInt();
if(marks >= 90)
System.out.println("Grade A+");
else if(marks >= 75)
System.out.println("Grade A");
else if(marks >= 60)
System.out.println("Grade B");
else if(marks >= 40)
System.out.println("Grade C");
else
System.out.println("Fail");
}
}

VDT:

Variable​ Data Type​ Description

marks​int​ Marks entered by user

Output: Enter marks: 88


Grade A
Program 12: Use of switch-case – Calculator

Problem: Perform basic arithmetic operations using switch-case.

import java.util.Scanner;
class Calculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, b, choice;
System.out.print("Enter first number: ");
a = sc.nextInt();
System.out.print("Enter second number: ");
b = sc.nextInt();
System.out.println("1.Add 2.Subtract 3.Multiply 4.Divide");
System.out.print("Enter choice: ");
choice = sc.nextInt();
switch(choice) {
case 1: System.out.println("Sum = " + (a + b)); break;
case 2: System.out.println("Difference = " + (a - b)); break;
case 3: System.out.println("Product = " + (a * b)); break;
case 4: System.out.println("Quotient = " + (a / b)); break;
default: System.out.println("Invalid choice");
}
}
}

VDT:

Variable​ Data Type​ Description

a, b​ int​ Operands
choice​int​ User operation choice

Output: Enter first number: 10


Enter second number: 5
1.Add 2.Subtract 3.Multiply 4.Divide
Enter choice: 3
Product = 50
Program 13: While Loop – Sum of First 10 Numbers

Problem: Print the sum of the first 10 natural numbers.

class WhileSum {
public static void main(String[] args) {
int i = 1, sum = 0;
while(i <= 10) {
sum += i;
i++;
}
System.out.println("Sum = " + sum);
}
}

VDT:

Variable​ Data Type​ Description

i​ int​ Loop counter


sum​ int​ Accumulated sum

Output: Sum = 55
Program 14: For Loop – Factorial of a Number

Problem: Find factorial of a number.

import java.util.Scanner;
class Factorial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, fact = 1;
System.out.print("Enter a number: ");
n = sc.nextInt();
for(int i = 1; i <= n; i++) {
fact *= i;
}
System.out.println("Factorial = " + fact);
}
}

VDT:

Variable​ Data Type​ Description

n​ int​ Number entered by user


i​ int​ Loop counter
fact​ int​ Result of factorial

Output: Enter a number: 5


Factorial = 120
Program 15: Nested if – Check Leap Year

Problem: Check whether a given year is a leap year.

import java.util.Scanner;
class LeapYear {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int year;
System.out.print("Enter year: ");
year = sc.nextInt();
if(year % 4 == 0) {
if(year % 100 == 0) {
if(year % 400 == 0)
System.out.println("Leap year");
else
System.out.println("Not a leap year");
} else
System.out.println("Leap year");
} else
System.out.println("Not a leap year");
}
}

VDT:

Variable​ Data Type​ Description

year​ int​ Year to be checked

Output: Enter year: 2000


Leap year
Program 16: Do-while Loop – Table of a Number

Problem: Print the multiplication table of a number using do-while loop.

import java.util.Scanner;
class TableDoWhile {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num, i = 1;
System.out.print("Enter number: ");
num = sc.nextInt();
do {
System.out.println(num + " x " + i + " = " + (num * i));
i++;
} while(i <= 10);
}
}

VDT:

Variable​ Data Type​ Description

num​ int​ Number for the table


i​ int​ Counter from 1 to 10

Output: Enter number: 6


6x1=6
6 x 2 = 12
... up to 6 x 10 = 60
Program 17: Accept String and Display

Problem: Accept a string and display it.

import java.util.Scanner;
class DisplayString {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a string: ");
String str = sc.nextLine();
System.out.println("You entered: " + str);
}
}

VDT:

Variable​ Data Type​ Description

str​ String​ String entered

Output: Enter a string: Hello Java


You entered: Hello Java
Program 18: Length of a String

Problem: Accept a string and display its length.

import java.util.Scanner;
class StringLength {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a string: ");
String str = sc.nextLine();
System.out.println("Length = " + str.length());
}
}

VDT:

Variable​ Data Type​ Description

str​ String​ Input string

Output: Enter a string: Hello


Length = 5
Program 19: Accept Character and Display ASCII

Problem: Accept a character and display its ASCII value.

import java.util.Scanner;
class CharASCII {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char ch;
System.out.print("Enter a character: ");
ch = sc.next().charAt(0);
int ascii = (int) ch;
System.out.println("ASCII value = " + ascii);
}
}

VDT:

Variable​ Data Type​ Description

ch​ char​ Input character


ascii​ int​ ASCII of character

Output: Enter a character: A


ASCII value = 65
Program 20: Use of Math Functions

Problem: Demonstrate use of basic Math functions.

import java.util.Scanner;
class MathDemo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double num;
System.out.print("Enter a number: ");
num = sc.nextDouble();
System.out.println("Square root = " + Math.sqrt(num));
System.out.println("Square = " + Math.pow(num, 2));
System.out.println("Cube = " + Math.pow(num, 3));
}
}

VDT:

Variable​ Data Type​ Description

num​ double​ Number entered

Output: Enter a number: 4


Square root = 2.0
Square = 16.0
Cube = 64.0
CONCLUSION
Through the completion of this project, I gained valuable experience and
a deeper understanding of Java programming concepts. Each program
gave me practical knowledge of how logical thinking can be applied to
solve real-life problems using code. It has also strengthened my
foundation in object-oriented programming.

This journey has not only improved my technical skills but also enhanced
my analytical thinking and creativity. I am confident that the skills I
developed during this project will assist me in future programming
challenges.
BIBLIOGRAPHY
1. Understanding Computer Applications with BlueJ - Avichal Publishing
Company

2. BlueJ IDE (used for executing and testing all Java programs)

3. ChatGPT (for guidance, formatting, and code verification)

4. Class Notes and Practical Sessions

You might also like