Programming

Fundamentals

using Java🚀 

Lecture

 

  • statements
  • branching
  • looping
  • coding problems

Statements

Instructions to the JVM to do something.

 

declarations,

assignments,

methods calls

input/output statements,

classes and objects

etc.

Conditional Statements

Single If

// Single If

int marks = 90;

if (marks > 80) {
	//print something
    
}

Conditional Statements

If-else block

// If-Else Block

int marks = 70;

if (marks > 80) {
	//print something
}
else{
	//some work
    
}

Conditional Statements

If-else-if-else block

// If-Else Block

int marks = 70;

if (marks > 80) {
	//do something
}
else if(marks>60){
	//do something
}
else{
	//do something
}

Ternary Operator

variable = (condition) ? expressionTrue :  expressionFalse;

Loops

Do something again & again!

 

While Loop

//Init 

while(..condition is true ..){
	
    //execute some stuff
    
    //update 
}
int calories_burnt = 0;

while(calories_burnt <100 ){
	
    System.out.println("running...");
    
    calories_burnt = calories_burnt + 1;
}

While Loop

int calories_burnt = 0;

while(calories_burnt<100 ){
    System.out.println("running...");
    calories_burnt = calories_burnt + 1;
}

//out of the loop
System.out.println("Done");

For Loop


for(init;stopping_condition;update_statement){
    //execute some stuff
}

Code Demo!

Number Sum 

Find the sum of numbers from 1 to N 

 

Example

N = 4

 

 

Output

10

Number Sum-II

Take input N, followed by N numbers find their sum.

 

Example

N = 4

 

 

Output

10

Prime Number

Given a Number, check if it is Prime or Not!

Input 

11

 

 

Output

Yes

Sum the Digits

Given a Number, print the sum of its digits.

Input 

11

 

 

Output

2

Time To Try!

8 Mins

Challenge 🔥 

Stair Pattern

 

*

***

*****

Challenge 🔥 

Triangle Pattern

 

 

*

***

*****

Challenge 🔥 

Print all Primes upto a number N.

 

 

 

Challenge 🔥 

Print all Primes upto a number N.

 

 

 

Programming fundamentals

By Prateek Narang

Programming fundamentals

  • 16