Tuesday, 6 July 2021

What is ladder if || Java Ladder if statement.

 Ladder if statement

If a if statement is used within an else statement then such a control structure is called as ladder if statement.

Syntax- 
if(condition) 
     Statements.. 
else
     if(condition) 
         statements.. 
    else 
         if(condition) 
              statements.. 
          else …. 

A ladder if is used to check a condition if some other condition is false


1) WAP to read a number and check if it is a positive no. or negative no or zero.

Program:- 
import java.util.Scanner;
public class easy
{
public static void main(String[] args)
{
Scanner likein=new Scanner(System.in);
System.out.print("Enter a Number:");
int a=likein.nextInt();
if(a>0)
System.out.println("Number is Positive..");
else
if(a<0)
System.out.println("Number is Negative..");
else
System.out.println("Number is Zero..");
}
}

Output:-
Enter a Number:
7
Number is Positive..

2) WAP to read 3 different nos. a , b and c. and find greatest of them.

program:- 
package com.company;
import java.util.Scanner;
class easy
{
public static void main(String[] args)
{
Scanner likein=new Scanner(System.in);
System.out.println("Enter 3 different Numbers:");
int a=likein.nextInt();
int b=likein.nextInt();
int c=likein.nextInt();
if(a>b && a>c)
System.out.println(a+" is Greatest");
else
if(b>c)
System.out.println(b+" is Greatest");
else
System.out.println(c+" is Greatest");
}
}

Output:- 
Enter 3 different Numbers:
7 14 17
17 is Greatest

3) WAP to read color code i.e. a char value and print appropriate
color according to code.
R - red
G - green
B - blue
any other char-white].

PROGRAM:-

import java.util.Scanner;
class easy
{
public static void main(String[] args)
{
Scanner likein=new Scanner(System.in);
System.out.print("Enter Color Code:");
String str=likein.next();
char ch=str.charAt(0);
//charAt method is used to get char from pos
if(ch=='r' || ch=='R')
System.out.println("Red");
else
if(ch=='g' || ch=='G')
System.out.println("Green");
else
if(ch=='b' || ch=='B')
System.out.println("Blue");
else
System.out.println("White");
}
}

oUTPUT:- 
Enter Color Code:
R
Red

what is Nested if Statement || Java Nested if

 Nested if statement


Nested if

If a if statement is used within if statement then such a control structure is called as nested if


if(condition) 
     if(condition) 
     { 
Statements…3
 ………………….. 
     } 
}

Nested If statement is used to check a condition only if another condition is true


WAP to read a number and check if it is a 2 digit no. or not. If it is a 2 digit no. then check if both digits are same or not.

program:- 

import java.util.Scanner;
public class easy
{
public static void main(String[] args)
{
Scanner likein=new Scanner(System.in);
System.out.print("Enter a Number:");
int a=likein.nextInt();
if(a>=10 && a<=99)
{
System.out.println("It is a 2 digit Number");
int x=a%10;
int y=a/10;
if(x==y)
System.out.println("Both digits are same");
else
System.out.println("Both digits are Not same");
}
else
System.out.println("It is not a 2 digit Number");
}
}

Output:- 
Enter a Number:22
It is a 2 digit Number
Both digits are same.

WAP to read a number and check if it is a positive number or not. If it is a positive number then
check if it is even or not.
program:- 
package com.company;
import java.util.Scanner;
public class easy
{
public static void main(String[] args)
{
Scanner likein=new Scanner(System.in);
System.out.print("Enter a Number:");
int a=likein.nextInt();
if(a>0)
{
System.out.println("Number is Positive");
if(a%2==0)
System.out.println("Even Number");
else
System.out.println("Odd Number");
}
else
System.out.println("Number is Not Positive");
}
}

Output:- 
Enter a Number:
44
Number is Positive
Even Number

WAP to read 3 angles and check if triangle can be formed or not. If triangle can be formed
then check if it is an isosceles or equilateral or right angled triangle.

package com.company;
import java.util.Scanner;
public class easy
{

public static void main(String[] args)
{
Scanner likein=new Scanner(System.in);
System.out.print("Enter 3 Angles:");
int a=likein.nextInt();
int b=likein.nextInt();
int c=likein.nextInt();
if(a+b+c==180)
{
System.out.println("Triangle can be formed");
if(a==b && b==c)
System.out.println("Eq.Triangle");
if(a==b || b==c || c==a)
System.out.println("Iso.Triangle");
if(a==90 || b==90 || c==90)
System.out.println("Rt.Ag.Triangle");
}
else
System.out.println("Triangle cannot be formed");
}
}
Output:- 
Enter 3 Angles:
90 60 30
Triangle can be formed
Rt.Ag.Triangle

Sunday, 4 July 2021

what is if statement || Conditional statement.

• Conditional Statements

• If statement 


Conditional statement

  •  These are statements within our program which are conditionally executed .
  •  To conditionally execute statement java provides us different control structures and operators.

  if statement 
 switch statement 
 Ternary/conditional operator

If statement


  • It is used to conditionally execute a block of statements.

Syntax:- 

if(condition)            
{
 statements
 ………………. 
else 
{
 statements 
……………….. 
next statement



 -> If condition is true then statements within if block are                                                                   executed and then program control is transferred to next statements.

->If condition is false then statements within else block are executed and then program control is transferred to next statements.
else part is optional.


Boolean expressions

  • Condition can be specified by using a Boolean expression i.e. an expression whose result is true or false

  • Boolean expression can be created by using relational and logical operators
  • Relational Operators: < , > , <= , >= , == , !=
  •  Logical Operators : && , || , !

  • WAP to read a number and check if it is an even or odd.
program:- 
package com.company;
import java.util.Scanner;
public class easy
{
public static void main(String args[])
{
Scanner likein=new Scanner(System.in);
System.out.print("Enter a Number:");
int a=likein.nextInt();
if(a%2==0)
System.out.println("Number is EVEN");
else
System.out.println("Number is ODD");
}
}

output:- 
Enter a Number: 8
Number is EVEN

  • WAP to read 3 angles and check if triangle can be formed or not.
program:-
package com.company;
import java.util.Scanner;
public class easy
{
public static void main(String args[])
{
Scanner likein=new Scanner(System.in);
System.out.print("Enter 3 angles:");
int a=likein.nextInt();
int b=likein.nextInt();
int c=likein.nextInt();
if(a+b+c==180)
System.out.println("Triangle can be formed");
else
System.out.println("Triangle cannot be formed");
}
}
output:- 
Enter 3 angles:100 60 20
Triangle can be formed



THANK YOU


Saturday, 3 July 2021

Naming Convention/Scanner Class || Introduction of Java (Part-4)

• Naming Conventions

• System.Out 

• System.in 

• Scanner Class

PROGRAM


Naming Conventions

class name, interface name – First Letter of each word must be in upper case and rest in lower case. – e.g. String, StringBuffer, FileInputStream, ActionListener etc.

 • method name, variable name – First word in lower case – For rest of words First Letter of each word must be in upper case and rest in lower case 

– e.g. main(), print(), drawLine(), drawRoundRect() , toUpperCase( ) etc. 

package name – should be in lowercase letter 

– e.g. java, lang, sql, util etc. 

constants name – should be in uppercase letter. – Words separated by underscore

 – e.g. RED, YELLOW, MAX_PRIORITY etc.


Program Input

Input to our java program can be provided by using different ways. 

Console Input (using System.in)

 – GUI Interface

 – Command Line Arguments

 – Input Dialog Box 




• System.out Object 

 • This object is attached to our standard output device.

 • This object is used to send data to standard output device. 

• It provides us methods print(), println(), printf()..

   etc to write data into the object .


• System.in Object 

• This object is attached to our standard input device. 

• This object is used to read data from standard input device.0 

• It provides us method read() to read raw/binary data from the object 


System.in

We can not directly easily use this System.in Object because it returns byte type of data.
 i.e. raw data

We have to wrap it in different objects to read its data such as 

– Scanner

 – BufferedReader

 – etc


Class Scanner – java.util


It is used to scan data from System.in Object. 

Scanner Object can be created by using syntax:-

 Scanner stdin=new Scanner(System.in);

methods:- 

String next() – it returns the next token/word from the scanner. 

String nextLine() – it returns the next line as a string.  

int nextInt() – it scans the next token as an int value.  

long nextLong() – it scans the next token as a long value. .

float nextFloat() – it scans the next token as a float value. 

double nextDouble() – it scans the next token as a double value.

  

Program's


  • WAP to read radius of circle and find its area and circumference.

package com.company;
import java.util.Scanner;
public class Easy
{
public static void main(String[] args)
{

Scanner likein=new Scanner(System.in);
System.out.print("Enter Radius ");
int r=likein.nextInt();
double a=3.14*r*r;
double c=2*3.14*r;
System.out.println("Area is "+a);
System.out.println("Circumference is "+c);
}
}

Output:- 

Enter Radius 
 6 
Area is 113.03999999999999
Circumference is 37.68


  • WAP to read length and breadth of rectangle and find its area and perimeter.

package com.company;
import java.util.Scanner;
public class Easy
{
public static void main(String[] args) {

Scanner likein =
new Scanner(System.in);
System.
out.print("Enter Length and Breadth:");
int l = likein.nextInt();
int b = likein.nextInt();

int a = l * b;
int p = 2 * (l + b);

System.
out.println("Area is " + a);
System.
out.println("Perimeter is " + p);
}
}

Output:- 

Enter Length and Breadth:
10 5
Area is 50
Perimeter is 30

Friday, 2 July 2021

What is JDK/JAVAC || Introduction of Java (part-3)

JDK

JAVAC



JDK – java development kit

  1. JDK Java development kit is provided by oracle(previously by sun system)
  2. Java development kit contains different tools for compilation, execution , documentation , debugging etc. 


 JAVAC

         This is java compiler.

 It is used to convert our java source code into byte code. 

 Syntax: javac filename

 It will create a class file(byte code) for all the classes present in specified file.

 For ex: javac first.java 

 


Thursday, 1 July 2021

Basic program of Java || introduction of 'JAVA' (Part-2)

 Format of Java Program

• Output Statements 

• First Program 


General Format of Java Program

Package statement 

Import statement

Global declaration 

class Class Name 

public static void main( String[] args ) 

    {  

Statements…..

……………………. 

     }

 }


Package statement

  1. The package statement defines a namespace in which classes are stored.
  2. For ex: package india..

Import statement

  1. Java provides us many library classes which are defined in different packages.
  2. If we want to use these classes then we have to import them.
  3.  For eg: – import java.awt.Button;
  4.  import java.awt.TextField; 
  5.  import java.awt;
Global Declaration
  1. In this global declaration we can define only user defined data types such as classes, interfaces.
  2. In this section we can not define variables or functions.
public static void main( String[] args )/Function Main

  • Execution of java program begins with function main. 
  • Function main must be in a class.
public:- It indicates that main function is assessable.
static:- it indicates that function main can be called without creating object.
void:-  it indicates that function main doesn't return any value.
String[] args:-  it is used to receive command line arguments.

Output Statements


System.out.print(value) 

-Will print value on standard output device 
-ex:
  1. System.out.print( “INDIA” ) ; 
  2.  System.out.print( 2121 ) ; 
  3.  System.out.print( 3.14 );

System.out.println(value) 

-Will print value and a new line char on standard output device 
- ex:
• System.out.println(  “JAVA PROGRAM” ) 

System.out.printf(“foramtString”,args…)

-Will print formatted String on standard output device 
 -ex:-
 float p = 3.14f; 
System.out.printf( “Value of PI is %f” , p ) ; 


First Program


PROGRAM


class Easy 
 { 
 public static void main(String[] args) 
   { 
 System.out.println(“HELLO WORLD”); 
    } 
 }

Output:-

:- HELLO WORLD



Introduction Of Java || Learn java (part-1)

 

Introduction of Java Programming:-

 What is Java:- 

             Java is Simple, Object Oriented, Robust, Secured, Dynamic, Distributed, Automatically garbage collected, Compiled and Interpreted, Platform Independent language used for internet programming.


Feature's of Java:- 

1.             Object Oriented

2.             Simple

3.              Robust

4.              Secured

5.             Dynamic

6.             Distributed

7.             Automatically garbage collected

8.             Platform Independent language

 

Explanation of Java Feature

Object Oriented

 Java is Object Oriented Language.

 It provides us programming environment where we can create objects and can perform operations on them.



Simple

It is easy to learn.

It is based on c and C++.

It removes all complicated features of c and  CPP such as pointers,  operator overloading, multiple inheritance, dynamic linking etc.

 Robust

 Strong type checking mechanism of Java helps in making Java Robust.

Java also has feature of Automatic memory management and garbage collection.

System crashing bugs, are very rare in Java.

 Secured

 Java's security model protect users from hostile programs downloaded from some un trusted resource within a network through "sandbox".

It allows all the Java programs to run inside the sandbox only and prevents many activities from un trusted resources such as reading or writing to the local disk, accessing network.



Dynamic


Some topics that are dynamic in java are

    1.   Dynamic polymorphism

 

Compiler doesn’t understand which method to called in advance.

jvm decide which method to called at run time.

2.   Dynamic memory allocation

 

 All Java objects are dynamically allocated.  

 

Distributed

 Java is a distributed language which means that the program can be design to run on computer networks.

To design such applications Java provides an extensive library of classes for communication and technology such as RMI.



  Automatically garbage collected

In java, garbage means unreferenced objects.

 Garbage Collection is process of reclaiming the runtime unused memory automatically. In other words, it is a way to destroy the unused objects.



 Platform Independent language





 

  THANK YOU.......

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

What is ladder if || Java Ladder if statement.

 Ladder if statement If a if statement is used within an else statement then such a control structure is called as ladder if statement. Synt...