SlideShare a Scribd company logo
Computational Problem
Solving
Table of Contents
Java Introduction
Data Types
Sum of two complex numbers
Multiply and Divide
Conditional Control Structure
Coin Change
Odd or even
Uppercase or Lowercase
Profit or Loss
Sum of N numbers
Factorial of a number
Fibonacci series
Armstrong Number
Reverse a number
Linear Search
Matrix Multiplication
Reverse an array
Minimum Sum
Remove duplicates
Closest Pair
String validation
Anagrams
Twin Prime
Vowel count
Maximum Sum
Longest Palindrome
Missing number
Reverse vowels
Reverse only letters
Power of three
Convert number to Hex
Basic Calculator
Perfect Squares
Spiral Matrix
Permutations
Student Attendance Record
Name password generation
Reverse String
Count even digits
Number Series
Diamond Series
Introduction
❑ Java is a general-purpose, high-level programming language .
❑ Java is a programming language that James Gosling developed at
Sun Microsystems_Inc in the year 1995, which later on was taken
into possession by the Oracle Corporation in 2009.
❑ Java Virtual Machine interprets the bytecode and converts it to
platform specific machine code. Hence, Java is also called a
platform-independent programming language.
❑ Java is a class-based object-oriented programming language that
implements the principle of write once code anywhere.
Features of Java
1. Simple
2. Object-Oriented
3. Portable
4. Platform independent
5. Secured
6. Robust
7. Architecture neutral
8. Interpreted
9. High Performance
10. Multithreaded
11. Distributed
12. Dynamic
Applications of Java
o Mobile App Development
o Desktop GUI Applications
o Web-based Applications
o Gaming Applications
o Big Data Technologies
o Distributed Applications
o Cloud-based Applications
o IoT Applications
o Enterprise Applications
o Scientific Applications
Data Types
There are two types of data types in Java:
Primitive data types : The primitive data types include:
o boolean data type
o byte data type
o char data type
o short data type
o int data type
o long data type
o float data type
o double data type
Non-primitive data types : The non-primitive data types include :
o Classes
o Interfaces
o Arrays.
Computational Problem Solving 004 (1).pptx (1).pdf
Example
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99f; // Floating point number
char myLetter = 'D’; // Character
boolean myBool = true; // Boolean
double d2 = 1.234e2 // Double
String myText = "Hello"; // String
int arr[] = new int[100]; // Array
If-else Statement
The if Statement:
If(condition) {
//block of code to be executed if the condition is true
}
Example :
int x = 20;
int y = 18;
if (x > y)
{
System.out.println("x is greater than y");
}
The else Statement:
If(condition) {
//block of code to be executed if the condition is true
}
else {
// block of code to be executed if the condition is false
}
Example :
int x = 20;
if (x > 18){
System.out.println("x is greater than 18");
}
else {
System.out.println("x is less than 18");
}
The else if Statement:
If(condition 1) {
//block of code to be executed if the condition 1 is true
} else if (condition 2) {
// block of code to be executed if the condition 1 is false and condition 2 is true
} else {
// block of code to be executed if the condition 1 is false and condition 2 is false
}
Example : int x = 0;
if (x > 0){
System.out.println("x is greater than 0");
} else if (x < 0) {
System.out.println("x is less than 0");
} else {
System.out.println("x is 0");
}
Loops in Java
for Loop:
for(initializing statement;testing condition;increment/decrement)
{
//code to be iterated
}
Example :
for (i = 0; i <= 10; i++)
{
System.out.println("Value of i = " + i);
}
while Loop:
while(boolean condition)
{
//statements;
}
Example :
while (i < 5) {
System.out.println("The value of i is = " + i);
i++;
}
do while Loop:
do {
statement(s);
} while(test-expression) ;
Example :
char ch = 'A' ;
do
{
System.out.println( ch + " " );
ch++;
} while(ch <= 'Z');
Arrays in Java
• In Java, all arrays are dynamically allocated.
• Arrays are stored in contagious memory.
• Since arrays are objects in Java, we can find their length using the
object property length.
• A Java array variable can also be declared like other variables with
[] after the data type.
• Java array can also be used as a static field, a local variable, or a
method parameter.
• The size of an array must be specified by int or short value and not
long.
Instantiating array:
var-name = new type [size];
int intArray[]; //declaring array
intArray = new int[20]; // allocating memory to array
int[] intArray = new int[20]; // combining both statements in one
Array Literal:
int[] intArray = new int[]{ 1,2,3,4,5,6,7,8,9,10 };
// Declaring array literal
THANK YOU

More Related Content

PPTX
Computational Problem Solving 016 (1).pptx
PPTX
control_javascript_for _beginners_and _pro.pptx
PDF
KeyJavaConcepts to EnhanceYour AutomationTesting Skills
PPTX
Java fundamentals
PDF
core java
PDF
java programming language part-2 decision making .pdf
PPT
Java Tutorial
PPT
Java tut1
Computational Problem Solving 016 (1).pptx
control_javascript_for _beginners_and _pro.pptx
KeyJavaConcepts to EnhanceYour AutomationTesting Skills
Java fundamentals
core java
java programming language part-2 decision making .pdf
Java Tutorial
Java tut1

Similar to Computational Problem Solving 004 (1).pptx (1).pdf (20)

PPT
Tutorial java
PPT
Java Tut1
PDF
java notes.pdf
PPT
C tutorial
PPTX
OOP-java-variables.pptx
PPTX
C Programming with oops Concept and Pointer
PDF
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
PPTX
03 and 04 .Operators, Expressions, working with the console and conditional s...
PDF
Loops and conditional statements
PPTX
Unit-02 Selection, Mathematical Functions and loops.pptx
PPT
Java tutorial PPT
PPT
Java tutorial PPT
PDF
Chapter 00 revision
PPTX
JAVA LOOP.pptx
PPTX
Java introduction
PPSX
Java Tutorial
PPTX
Java Basics 1.pptx
ODP
Synapseindia reviews.odp.
PPT
Java tut1
Tutorial java
Java Tut1
java notes.pdf
C tutorial
OOP-java-variables.pptx
C Programming with oops Concept and Pointer
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
03 and 04 .Operators, Expressions, working with the console and conditional s...
Loops and conditional statements
Unit-02 Selection, Mathematical Functions and loops.pptx
Java tutorial PPT
Java tutorial PPT
Chapter 00 revision
JAVA LOOP.pptx
Java introduction
Java Tutorial
Java Basics 1.pptx
Synapseindia reviews.odp.
Java tut1
Ad

Recently uploaded (20)

DOCX
The Five Best AI Cover Tools in 2025.docx
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PDF
Become an Agentblazer Champion Challenge Kickoff
PPTX
Mastering-Cybersecurity-The-Crucial-Role-of-Antivirus-Support-Services.pptx
PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Benefits of DCCM for Genesys Contact Center
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PDF
How to Confidently Manage Project Budgets
PPTX
CRUISE TICKETING SYSTEM | CRUISE RESERVATION SOFTWARE
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
The Role of Automation and AI in EHS Management for Data Centers.pdf
PDF
Become an Agentblazer Champion Challenge
PDF
Understanding NFT Marketplace Development_ Trends and Innovations.pdf
PPTX
How a Careem Clone App Allows You to Compete with Large Mobility Brands
PDF
Build Multi-agent using Agent Development Kit
The Five Best AI Cover Tools in 2025.docx
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
Materi_Pemrograman_Komputer-Looping.pptx
Become an Agentblazer Champion Challenge Kickoff
Mastering-Cybersecurity-The-Crucial-Role-of-Antivirus-Support-Services.pptx
A REACT POMODORO TIMER WEB APPLICATION.pdf
ManageIQ - Sprint 268 Review - Slide Deck
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
How to Migrate SBCGlobal Email to Yahoo Easily
Benefits of DCCM for Genesys Contact Center
Materi-Enum-and-Record-Data-Type (1).pptx
How to Confidently Manage Project Budgets
CRUISE TICKETING SYSTEM | CRUISE RESERVATION SOFTWARE
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
How Creative Agencies Leverage Project Management Software.pdf
The Role of Automation and AI in EHS Management for Data Centers.pdf
Become an Agentblazer Champion Challenge
Understanding NFT Marketplace Development_ Trends and Innovations.pdf
How a Careem Clone App Allows You to Compete with Large Mobility Brands
Build Multi-agent using Agent Development Kit
Ad

Computational Problem Solving 004 (1).pptx (1).pdf

  • 2. Table of Contents Java Introduction Data Types Sum of two complex numbers Multiply and Divide Conditional Control Structure Coin Change Odd or even Uppercase or Lowercase Profit or Loss Sum of N numbers Factorial of a number Fibonacci series Armstrong Number Reverse a number Linear Search Matrix Multiplication Reverse an array Minimum Sum Remove duplicates Closest Pair String validation Anagrams Twin Prime Vowel count Maximum Sum Longest Palindrome Missing number Reverse vowels
  • 3. Reverse only letters Power of three Convert number to Hex Basic Calculator Perfect Squares Spiral Matrix Permutations Student Attendance Record Name password generation Reverse String Count even digits Number Series Diamond Series
  • 4. Introduction ❑ Java is a general-purpose, high-level programming language . ❑ Java is a programming language that James Gosling developed at Sun Microsystems_Inc in the year 1995, which later on was taken into possession by the Oracle Corporation in 2009. ❑ Java Virtual Machine interprets the bytecode and converts it to platform specific machine code. Hence, Java is also called a platform-independent programming language. ❑ Java is a class-based object-oriented programming language that implements the principle of write once code anywhere.
  • 5. Features of Java 1. Simple 2. Object-Oriented 3. Portable 4. Platform independent 5. Secured 6. Robust 7. Architecture neutral 8. Interpreted 9. High Performance 10. Multithreaded 11. Distributed 12. Dynamic
  • 6. Applications of Java o Mobile App Development o Desktop GUI Applications o Web-based Applications o Gaming Applications o Big Data Technologies o Distributed Applications o Cloud-based Applications o IoT Applications o Enterprise Applications o Scientific Applications
  • 7. Data Types There are two types of data types in Java: Primitive data types : The primitive data types include: o boolean data type o byte data type o char data type o short data type o int data type o long data type o float data type o double data type Non-primitive data types : The non-primitive data types include : o Classes o Interfaces o Arrays.
  • 9. Example int myNum = 5; // Integer (whole number) float myFloatNum = 5.99f; // Floating point number char myLetter = 'D’; // Character boolean myBool = true; // Boolean double d2 = 1.234e2 // Double String myText = "Hello"; // String int arr[] = new int[100]; // Array
  • 10. If-else Statement The if Statement: If(condition) { //block of code to be executed if the condition is true } Example : int x = 20; int y = 18; if (x > y) { System.out.println("x is greater than y"); }
  • 11. The else Statement: If(condition) { //block of code to be executed if the condition is true } else { // block of code to be executed if the condition is false } Example : int x = 20; if (x > 18){ System.out.println("x is greater than 18"); } else { System.out.println("x is less than 18"); }
  • 12. The else if Statement: If(condition 1) { //block of code to be executed if the condition 1 is true } else if (condition 2) { // block of code to be executed if the condition 1 is false and condition 2 is true } else { // block of code to be executed if the condition 1 is false and condition 2 is false } Example : int x = 0; if (x > 0){ System.out.println("x is greater than 0"); } else if (x < 0) { System.out.println("x is less than 0"); } else { System.out.println("x is 0"); }
  • 13. Loops in Java for Loop: for(initializing statement;testing condition;increment/decrement) { //code to be iterated } Example : for (i = 0; i <= 10; i++) { System.out.println("Value of i = " + i); }
  • 14. while Loop: while(boolean condition) { //statements; } Example : while (i < 5) { System.out.println("The value of i is = " + i); i++; }
  • 15. do while Loop: do { statement(s); } while(test-expression) ; Example : char ch = 'A' ; do { System.out.println( ch + " " ); ch++; } while(ch <= 'Z');
  • 16. Arrays in Java • In Java, all arrays are dynamically allocated. • Arrays are stored in contagious memory. • Since arrays are objects in Java, we can find their length using the object property length. • A Java array variable can also be declared like other variables with [] after the data type. • Java array can also be used as a static field, a local variable, or a method parameter. • The size of an array must be specified by int or short value and not long.
  • 17. Instantiating array: var-name = new type [size]; int intArray[]; //declaring array intArray = new int[20]; // allocating memory to array int[] intArray = new int[20]; // combining both statements in one Array Literal: int[] intArray = new int[]{ 1,2,3,4,5,6,7,8,9,10 }; // Declaring array literal