Thursday 26 March 2020

FINDING SMALLER AMONG ALL USING JAVA LANGUAGE

Q-33-  If the ages of Rahul, Ayush and Ajay are input through the keyboard, write a java program to determine the elder among them.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int Rahul;
int Ayush;
int Ajay;
System.out.println("Enter The Ages Of Rahul ,Ayush And Ajay : ");
Rahul=sc.nextInt();
Ayush=sc.nextInt();
Ajay=sc.nextInt();
if(Rahul>Ayush && Rahul>Ajay)
{
System.out.println("Rahul Is Elder Among Them.");
}
else if(Ayush>Ajay && Ayush>Rahul)
{
System.out.println("Ayush Is Elder Among Them.");
}
else if(Ajay>Rahul && Ajay>Ayush)
{
System.out.println("Ajay Is Elder Among Them.");
}
}
}



OUTPUT :
Enter The Ages Of Rahul ,Ayush And Ajay :
16  15  17

Ajay Is Elder Among Them.

FINDING COORDINATE USING JAVA LANGUAGE

Q-32- Write a java program that takes the x – y coordinates of a point in the Cartesian plane and prints a message telling either an axis on which the point lies or the quadrant in which it is found.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner (System.in);
double x, y;
System.out.println("Enter The Value Of x and y :");
x=sc.nextDouble();
y=sc.nextDouble();
if(x==0 && y==0)
{
System.out.println("("+x+", "+y+") is on the Origin.");
}
else if(x==0 && y>0)
{
System.out.println("("+x+" , "+y+") is on the Y-axis.");
}
else if(x>0 && y==0)
{
System.out.println("("+x+" , "+y+") is on the X-axis.");
}
else if(x==0 && y<0)
{
System.out.println("("+x+" , "+y+") is on the Y-axis.");
}
else if(x<0 && y==0)
{
System.out.println("("+x+" , "+y+") is on the X-axis.");
}
else if(x>0 && y>0)
{
System.out.println("("+x+", "+y+") is on the First Quadrant.");
}
else if(x<0 && y>0)
{
System.out.println("("+x+" , "+y+") is on the Second Quadrant.");
}
else if(x<0 && y<0)
{
System.out.println("("+x+" , "+y+") is on the Third Quadrant.");
}
else if(x>0 && y<0)
{
System.out.println("("+x+" , "+y+") is on the Fourth Quadrant.");
}

}


}

OUTPUT :
Enter The Value Of x and y :
-1 -2.5

(-1.0 , -2.5) is on the Third Quadrant.

Enter The Value Of x and y :
0
4.8
(0.0 , 4.8) is on the Y-axis.


SOLVING LINEAR EQUATION USING CRAMER'S RULE BY JAVA LANGUAGE

Q-31- You can use Cramer’s rule to solve the following  2 X 2 system of linear equation:

𝑎𝑥 + 𝑏𝑦 = 𝑒     
𝑐𝑥 + 𝑑𝑦 = 𝑓
                           x=(𝑒𝑑 − 𝑏𝑓) /(𝑎𝑑 − 𝑏𝑐)                  𝑦 =(𝑎𝑓 − 𝑒𝑐)/ (𝑎𝑑 − 𝑏𝑐)

Write a java program that prompts the user to enter a, b, c, d, e, and f and displays the result. If (ad - bc) is 0, report that “The equation has no solution.”

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double a ,b ,c ,d ,e ,f ;
double x , y ,z;
System.out.println("Enter The Value Of a ,b ,c ,d ,e ,f :");
a=sc.nextDouble();
b=sc.nextDouble();
c=sc.nextDouble();
d=sc.nextDouble();
e=sc.nextDouble();
f=sc.nextDouble();
z=a*d-b*c;
x=(e*d-b*f)/z;
y=(a*f-e*c)/z;
if(z==0)
{
System.out.println("The Equation Has No Solution.");
}
else
{
System.out.println("x is "+x+" and y is "+y);
}
}


}

OUTPUT :
Enter The Value Of a ,b ,c ,d ,e ,f :
9.0 4.0 3.0 -5.0 -6.0 -21.0

x is -2.0 and y is 3.0

Enter The Value Of a ,b ,c ,d ,e ,f :
 1.0 2.0 2.0 4.0 4.0 5.0 
The Equation Has No Solution.


FINDING ROOTS OF A QUADRATIC EQUATION USING JAVA LANGUAGE

Q-30- The two roots of a quadratic equation 𝑎𝑥2 + 𝑏𝑥 + 𝑐 = 0  can be obtained using the following formula:

𝑟1 = −𝑏+√𝑏2−4𝑎𝑐 2𝑎         and           𝑟2 = −𝑏−√𝑏2−4𝑎𝑐 2𝑎
 b2 - 4ac is called the discriminant of the quadratic equation. If it is positive, the equation has two real roots. If it is zero, the equation has one root. If it is negative, the equation has no real roots.
Write a java program that prompts the user to enter values for a, b, and c and displays the result based on the discriminant. If the discriminant is positive, display two roots. If the discriminant is 0, display one root. Otherwise, display “The equation has no real roots” Note that you can use Math.pow(x, 0.5) to compute √𝑥

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double a ,b ,c;
double d ,r1 ,r2;
System.out.println("Enter The Value Of a ,b ,c :");
a=sc.nextDouble();
b=sc.nextDouble();
c=sc.nextDouble();
d = b*b-4*a*c;
double D=Math.pow(d, 0.5);
r1=(-b+D)/2*a;
r2=(-b-D)/2*a;
if(d==0)
{
System.out.println("The Equation Has One Root "+r1);
}
else if(d>0)
{
System.out.println("The Equation Has Two Real Roots "+r1+" and "+r2);
}
else if(d<0)
{
System.out.println("The Equation Has No Real Roots.");
}


}


}

OUTPUT :
Enter The Value Of a ,b ,c :
1 3 1

The Equation Has Two Real Roots -0.3819660112501051 and -2.618033988749895

Enter The Value Of a ,b ,c :
1 2 1
The Equation Has One Root -1.0

Enter The Value Of a ,b ,c :
1 2 3
The Equation Has No Real Roots.


FINDING LETTERS, NUMBERS AND SPECIAL CHARACTERS USING JAVA LANGUAGE

Q-29- Any character is entered through the keyboard, write a java program to determine whether the character entered is a capital letter, a small case letter, a digit or a special symbol. The following table shows the range of ASCII values for various characters.  Characters ASCII Values 
A – Z 65 – 90 
a – z 97 – 122
0 – 9 48 – 57 
special symbols 0 - 47, 58 - 64, 91 - 96, 123 – 127

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
char ch;
System.out.println("Enter The Character :");
ch=sc.next().charAt(0);
if(ch>=65 && ch<=90)
{
System.out.println("This Character Is A Capital Letter. ");
}
else if(ch>=97 && ch<=122)
{
System.out.println("This Character Is A Small Letter. ");
}
else if(ch>=48 && ch<=57)
{
System.out.println("This Character Is A Digit.");
}
else if((ch>=0 && ch<=47) || (ch>=58 && ch<=64)
|| (ch>=91 && ch<=96) || (ch>=123 && ch<=127))
{
System.out.println("This Character Is A Special Symbol.");
}
else
{
System.out.println("You Have Entered Something Different.");
}

}


}

OUTPUT :
Enter The Character :
A

This Character Is A Capital Letter.

Enter The Character :
a
This Character Is A Small Letter.

Enter The Character :
5
This Character Is A Digit.

Enter The Character :
*
This Character Is A Special Symbol.


EVEN OR ODD USING JAVA LANGUAGE

Q-28- Input an integer through the keyboard. Write a java program to find out whether it is an odd number or even number.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int num;
System.out.println("Enter The Number :");
num=sc.nextInt();
if(num%2==0)
{
System.out.println("It Is An Even Number.");
}
else
{
System.out.println("It Is An Odd Number.");
}
}


}

OUTPUT :
Enter The Number :
4

It Is An Even Number.

Enter The Number :
5
It Is An Odd Number.

STUDENT MARKING PROCESS USING JAVA LANGUAGE

Q-27-Write a java program to input the mark of a student and check if the student mark is greater than or equal to 40, then it generates the following message.  “Congratulation! You have passed the exam.”  Otherwise the output message is  “Sorry! You have failed the exam.”

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int mark;
System.out.println("Enter The Mark You Have Secured :");
mark=sc.nextInt();
if(mark>=40 )
{
 if(mark<=100)
 {
  System.out.println("Congratulation ! You Have Passed The Exam.");
 }
 else
 {
  System.out.println("Oops! You Have Entered Wrong Input....");
 }
}
else
{
System.out.println("Sorry! You Have Failed The Exam.");
}
}


}

OUTPUT :
Enter The Mark You Have Secured :
39

Sorry! You Have Failed The Exam.

Enter The Mark You Have Secured :
73
Congratulation ! You Have Passed The Exam.

Monday 23 March 2020

MEASUREMENT PROGRAM USING JAVA LANGUAGE

Q-26- Write a java program to input the height of the person and check if the height of the person is greater than or equal to 6 feet then print the message “The person is tall”.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
double height;
System.out.println("Enter The Height Of The Person In Feet :");
height=sc.nextDouble();
if(height>=6)
{
System.out.println("The Person Is Tall.");
}
else
{
System.out.println("Mummy Ne Complan Nahin Pilaya.....");
}
}


}

OUTPUT :
Enter The Height Of The Person In Feet :
6

The Person Is Tall.

Enter The Height Of The Person In Feet :
5.9
Mummy Ne Complan Nahin Pilaya.....

CONVERTING MINUTES INTO YEARS AND DAYS

Q-25- Write a java program that prompts the user to enter the minutes (e.g., 1 billion), and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int number;
System.out.println("Enter The Number Of Minutes: ");
number =sc.nextInt();
int minutesinayear=365*24*60;
int minutesinaday=24*60;
int year=number/minutesinayear;
int number1=number%minutesinayear;
int days=number1/minutesinaday;
System.out.println(number+" minutes is approximately "+year+" years and "+days+" days.");

}


}

OUTPUT :
Enter The Number Of Minutes:
1000000000

1000000000 minutes is approximately 1902 years and 214 days.

COUNTING NUMBERS OF EGG IN FORM OF GROSS AND DOZEN USING JAVA LANGUAGE

Q-24- If you have N eggs, then you have N/12 dozen eggs, with N%12 eggs left over. (This is essentially the definition of the / and % operators for integers.) Write a java program that asks the user how many eggs she has and then tells the user how many dozen eggs she has and how many extra eggs are left over. A gross of eggs is equal to 144 eggs. Extend your program so that it will tell the user how many gross, how many dozen, and how many left over eggs she has. For example, if the user says that she has 1342 eggs, and then your program would respond with 

        Your number of eggs is 9 gross, 3 dozen, and 10.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int number;
System.out.println("Enter The Number Of Eggs: ");
number=sc.nextInt();
int gross=number/144;
int a=number%144;
int dozen=a/12;
int b=a%12;
System.out.println("Your Number Of Eggs Is "+gross+" gross ,"+dozen+" dozen ,"+" and "+b);
}


}

OUTPUT :
Enter The Number Of Eggs:
1324

Your Number Of Eggs Is 9 gross ,2 dozen , and 4

AREA OF A TRIANGLE USING JAVA LANGUAGE

Q-23-Write a java program that prompts the user to enter three points (x1, y1), (x2, y2), (x3, y3) of a triangle and displays its area. The formula for computing the area of a triangle is

    s = (side1 + side2 + side3)/2;
    𝑎𝑟𝑒𝑎 = √𝑠 ∗ (𝑠 − 𝑎) ∗ (𝑠 − 𝑏) ∗ (𝑠 − 𝑐)

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double x1,y1,x2,y2,x3,y3;
System.out.println("Enter The Points For A Triangle :");
x1=sc.nextDouble();
y1=sc.nextDouble();
x2=sc.nextDouble();
y2=sc.nextDouble();
x3=sc.nextDouble();
y3=sc.nextDouble();
double a=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
double side1=Math.pow(a, 0.5);
double b=(x3-x2)*(x3-x2)+(y3-y2)*(y3-y2);
double side2=Math.pow(b, 0.5);
double c=(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3);
double side3=Math.pow(c, 0.5);
double s=(side1+side2+side3)/2;
double d=s*(s-side1)*(s-side2)*(s-side3);
double area=Math.pow(d, 0.5);
System.out.println("The Area Of The Triangle Is :"+area);
}


}

OUTPUT :
Enter The Points For A Triangle :
1.5
-3.4
4.6
5
9.5
-3.4

The Area Of The Triangle Is :33.600000000000016

DISTANCE BETWEEN TWO POINTS USING JAVA LANGUAGE

Q-22- Write a java program that prompts the user to enter two points (x1, y1) and (x2, y2) and displays their distance between them. The formula for computing the distance is √(𝑥2 − 𝑥1)2 + (𝑦2 − 𝑦1)2.  Note that you can use Math.pow (a, 0.5) to compute √𝑎.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double x1,x2,y1,y2;
System.out.println("Enter x1 and y1:" );
x1=sc.nextDouble();
y1=sc.nextDouble();
System.out.println("Enter x2 and y2:" );
x2=sc.nextDouble();
y2=sc.nextDouble();
double p=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
double distance=Math.pow(p,0.5);
System.out.println("The Distance Between The Two Points is : "+distance);

}


}

OUTPUT :
Enter x1 and y1:
1.5
-3.4
Enter x2 and y2:
4
5

The Distance Between The Two Points is : 8.764131445842194

DISPLAYING POWER USING JAVA LANGUAGE

Q-21-Write a java program that displays the following table. Cast floating-point numbers into integers.

a  b  pow(a, b)                           
1  2       1                                                                                                           
 2  3       8                                                                                                                                             
3  4       81                                                                                                                                           
 4  5      1024                                                                                                                                         
5  6      15625

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int a;
int b;
System.out.println("Enter The Value Of a & b :");
a=sc.nextInt();
b=sc.nextInt();
System.out.println("a    b     pow(a,b)");
System.out.println(   a+ "    "+b +"      "+ Math.pow(a, b));
System.out.println(   ++a+ "    "+ ++b +"      " + Math.pow(a, b));
System.out.println(   ++a+ "    "+ ++b +"      " + Math.pow(a, b));
System.out.println(   ++a+ "    "+ ++b +"      " + Math.pow(a, b));
System.out.println(   ++a+ "    "+ ++b +"      " + Math.pow(a, b));
}


}

OUTPUT :
Enter The Value Of a & b :
1
2
a    b     pow(a,b)
1    2      1.0
2    3      8.0
3    4      81.0
4    5      1024.0

5    6      15625.0

DISPLAYING AREA OF A HEXAGON USING JAVA LANGUAGE

Q-20- Write a java program that prompts the user to enter the side of a hexagon and displays its area. The formula for computing the area of a hexagon is

                                         𝐴𝑟𝑒𝑎 =3√3*X*X /2
where s is the length of a side.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double side;
System.out.println("Enter The Side:");
side=sc.nextDouble();
double p=Math.pow(3, 0.5);
double area=3*p*side*side/2;
System.out.println("The Area Of The Hexagon Is: "+area);
}


}

OUTPUT :
Enter The Side:
5.5

The Area Of The Hexagon Is: 78.59180539343781

MEASURING BODY MASS INDEX (BMI) USING JAVA LANGUAGE

Q-19- Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and dividing by the square of your height in meters. Write a java program that prompts the user to enter a weight in pounds and height in inches and displays the BMI.  Note that one pound is 0.45359237 kilograms and one inch is 0.0254 meters. 

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double pound,inch;
System.out.println("Enter The Weight In Pounds:");
pound=sc.nextDouble();
System.out.println("Enter The Height In Inches:");
inch=sc.nextDouble();
double weight=pound*0.45359237;
double height=inch*0.0254;
double bmi=weight/(height*height);
System.out.println("BMI is "+bmi);
}


}

OUTPUT :
Enter The Weight In Pounds:
95.5
Enter The Height In Inches:
50

BMI is 26.857257942215885

GETTING ACCELERATION USING JAVA LANGUAGE

Q-18-Average acceleration is defined as the change of velocity divided by the time taken to make the  change, as shown in the following formula:

                                   𝑎 =𝑣1−𝑣0 /𝑡
 Write a java program that prompts the user to enter the starting velocity v0 in meters/second, the ending velocity v1 in meters/second, and the time span t in seconds, and displays the average acceleration.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double v0,v1,t;
System.out.println("Enter v0,v1 and t:");
v0=sc.nextDouble();
v1=sc.nextDouble();
t=sc.nextDouble();
double a=(v1-v0)/t;
System.out.println("The average acceleration is :"+a);
}


}

OUTPUT :
Enter v0, v1 and t:
5.5
50.9
4.5

The average acceleration is :10.088888888888889

ADDING DIGITS IN AN INTEGER USING JAVA LANGUAGE

Q-17-Write a java program that reads an integer between 0 and 1000 and adds all the digits in the integer. For example, if an integer is 932, the sum of all its digits is 14.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int number;
System.out.println("Enter a number between 0 and 1000:");
number=sc.nextInt();
int a=number%10;
int a1=number/10;
int b=a1%10;
int b1=a1/10;
int c=b1%10;
int sum=a+b+c;
System.out.println("The sum of the digits is "+sum);
}


}

OUTPUT :
Enter a number between 0 and 1000:
932

The sum of the digits is 14

CONVERTING FEET TO METER USING JAVA LANGUAGE

Q-16- Write a java program that reads a number in feet, converts it to meters, and displays the result. One foot is 0.305 meter.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double feet;
System.out.println("Enter A Value For Feet :");
feet=sc.nextDouble();
double meter=feet*0.305;
System.out.println(feet+" Feet Is "+meter+" Meters");
}


}

OUTPUT :
Enter A Value For Feet :
16.5

16.5 Feet Is 5.0325 Meters

COMPUTING AREA AND VOLUME USING JAVA LANGUAGE

Q-15- Write a java program that reads in the radius and length of a cylinder and computes the area and volume using the following formulas:
           area = radius * radius * π
           volume = area * length

INPUT :
 import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double radius;
double length;
System.out.println("Enter The Radius And Length Of A Cylinder:");
radius=sc.nextDouble();
length=sc.nextDouble();
double area=3.141*radius*radius;
double volume=area*length;
System.out.println("The Area Is "+area);
System.out.println("The Volume Is "+volume);
}

}

OUTPUT :
 Enter The Radius And Length Of A Cylinder:
5.5
12
The Area Is 95.01525000000001
The Volume Is 1140.183

CONVERTING CELSIUS TO FAHRENHEIT USING JAVA LANGUAGE

Q-14-Write a java program that reads a Celsius degree in a double value from the console, then converts it to Fahrenheit and displays the result. The formula for the conversion is as follows:                                                        fahrenheit = (9 / 5) * celsius + 32

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
double celsius;
System.out.println("Enter The Degree In Celsius :");
celsius=sc.nextDouble();
double fahrenheit=((9.0/5.0)*celsius)+32;
System.out.println(celsius+" Celsius Is "+fahrenheit+" Fahrenheit");
}


}

OUTPUT :
Enter The Degree In Celsius :
43

43.0 Celsius Is 109.4 Fahrenheit

STRING CONCATENATION USING JAVA LANGUAGE

Q-13- Assume a string variable ruler1 contains “1” initially i.e.     String   ruler1=”1” Write a java program to print the following output using string concatenation. (You can take extra string variables)

             1
             1 2 1
             1 2 1 3 1 2 1
             1 2 1 3 1 2 1 4 1 2 1 3 1 2 1

INPUT :
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
String ruler1="1";
System.out.println(ruler1);
System.out.println(ruler1+" 2 "+ruler1);
ruler1=ruler1+" 2 "+ruler1;
System.out.println(ruler1+" 3 "+ruler1);
ruler1=ruler1+" 3 "+ruler1;
System.out.println(ruler1+" 4 "+ruler1);
}


}

OUTPUT :
1
1 2 1
1 2 1 3 1 2 1

1 2 1 3 1 2 1 4 1 2 1 3 1 2 1

USES OF VARIABLE DOUBLE USING JAVA LANGUAGE

Q-12-Suppose that a variable a is declared as double a = 3.14159. What do each of the following     print?

          a. System.out.println(a);
          b. System.out.println(a+1); 
          c. System.out.println(8/(int) a);
          d. System.out.println(8/a);
          e. System.out.println((int) (8/a));

INPUT :
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
double a=3.14159;
System.out.println(a);
System.out.println(a+1);
System.out.println(8/(int) a);
System.out.println(8/a);
System.out.println((int) (8/a));
}


}

OUTPUT :
3.14159
4.14159
2
2.5464812403910124

2

USING INTEGER MAXIMUM VALUE IN JAVA LANGUAGE

Q-11- Suppose that a variable a is declared as int a = 2147483647   (or equivalently,                                      Integer.MAX_VALUE ). What do each of the following print?

           a. System.out.println(a);
           b. System.out.println(a+1);
           c. System.out.println(2-a);
           d. System.out.println(-2-a);
           e. System.out.println(2*a);
           f. System.out.println(4*a);

INPUT :
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
int a=2147483647;
System.out.println(a);
System.out.println(a+1);
System.out.println(2-a);
System.out.println(-2-a);
System.out.println(2*a);
System.out.println(4*a);
}


}

OUTPUT :
 2147483647
-2147483648
-2147483645
2147483647
-2
-4

PRINTING NUMBERS AND LETTERS USING JAVA LANGUAGE

Q-10- What do each of the following print?
           a. System.out.println('b');
           b. System.out.println('b' + 'c');
           c. System.out.println((char) ('a' + 4));

INPUT :
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println('b');
System.out.println('b'+'c');
System.out.println((char) ('a'+4));
}


}

OUTPUT :
b
197

e

PRINTING NUMBERS AND LETTERS USING JAVA LANGUAGE

Q-9- What do each of the following print?
        a.System.out.println(2 + "bc");
        b.System.out.println(2 + 3 + "bc");
        c.System.out.println((2+3) + "bc");
        d.System.out.println("bc" + (2+3));
        e.System.out.println("bc" + 2 + 3);

INPUT :
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(2+"bc");
System.out.println(2+3+"bc");
System.out.println((2+3)+"bc");
System.out.println("bc"+(2+3));
System.out.println("bc"+2+3);
}


}

OUTPUT :
2bc
5bc
5bc
bc5

bc23

EXCHANGE VALUE USING JAVA LANGUAGE

Q-8-Write a java program to exchange the values of two variables of integer type A and B without using third temporary variable.
INPUT :
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
int a=10;
int b=20;
a=a+b;
b=a-b;
a=a-b;
System.out.println(a);
System.out.println(b);
}

}

OUTPUT :
20

10

EXCHANGE VALUES USING JAVA LANGUAGE

Q-7-Write a java program to exchange the values of two variables of integer type A and B using third temporary variable C. 
INPUT :
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
int a=10;
int b=20;
int c ;
c=a;
a=b;
b=c;
System.out.println(a);
System.out.println(b);
}


}

OUTPUT :
20
10

DISPLAYING MESSAGE USING JAVA LANGUAGE

Q-6- Let we have two values 113, 2.71828. Then, declare two different variables to hold the given values. Write the java program to display the values of these two variables on the screen, one per line.
INPUT :
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
int a=113;
double b=2.71828;
System.out.println("This is room # "+ a);
System.out.println("e is close to "+ b);
}

}

OUTPUT :
This is room # 113

e is close to 2.71828

PRINTING A MESSAGE USING JAVA LANGUAGE

Q-5- Write a java program that stores your Regd. No and year of admission into two variables, and displays their values on the screen.
INPUT :
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
 int Regd_no=1941012335;
 int year=2019;
 System.out.println("My Regd. No is "+ Regd_no +" and I have taken admission in B.Tech In " +year);
}

}

OUTPUT :
My Regd. No is 1941012335 and I have taken admission in B.Tech In 2019

PRINTING STAR PATTERN USING JAVA LANGUAGE

Q-4-Write a java program to print an equilateral triangle using star ' * '.
INPUT :
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub

System.out.println("         *          ");
System.out.println("        * *         ");
System.out.println("       * * *        ");
System.out.println("      * * * *       ");
System.out.println("     * * * * *      ");
System.out.println("    * * * * * *     ");
System.out.println("   * * * * * * *    ");
System.out.println("  * * * * * * * *   ");
}

}

OUTPUT :
         *          
        * *         
       * * *        
      * * * *       
     * * * * *      
    * * * * * *     
   * * * * * * *    
  * * * * * * * *   

PRINTING A MESSAGE USING JAVA LANGUAGE

Q-3- Write a java program to display your initials on the screen in block letters as shown. For   example the name Kanha Nayak.
INPUT :
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub

System.out.println("         K        K        NN             N     ");
System.out.println("         K      K          N N            N     ");
System.out.println("         K    K            N  N           N     ");
System.out.println("         K  K              N    N         N     ");
System.out.println("         KK                N      N       N     ");
System.out.println("         K  K              N        N     N     ");
System.out.println("         K    K            N          N   N     ");
System.out.println("         K      K          N            N N     ");
System.out.println("         K        K        N             NN     ");
}

}

OUTPUT :
         K        K        NN             N     
         K      K          N N            N     
         K    K            N  N           N     
         K  K              N    N         N     
         KK                N      N       N     
         K  K              N        N     N     
         K    K            N          N   N     
         K      K          N            N N     
         K        K        N             NN     

Sunday 22 March 2020

MAKING DESIGN USING JAVA LANGUAGE

Q-2-Write a java program that displays your name and address on the screen as if it were a letter.    Your output should look something like that below
INPUT :
public class NCM {

public static void main(String[] args) {

System.out.println("+--------------------------------------------------------+");
System.out.println("|                                                                             #### |");
System.out.println("|                                                                             #### |");
System.out.println("|                                                                             #### |");
System.out.println("|                                                                                         |");
System.out.println("|                                                                                         |");
System.out.println("|                                                 Kanha Nayak               |");
System.out.println("|                                                 Plot No.-408,Aiginia  |");
System.out.println("|                                                 Bhubaneswar               |");
System.out.println("|                                                                                         |");
System.out.println("+--------------------------------------------------------+");
}

}

OUTPUT :

+--------------------------------------------------------+

|                                                                             #### |

|                                                                             #### |

|                                                                             #### |
|                                                                                         |
|                                                                                         |
|                                                 Kanha Nayak               |
|                                                 Plot No.-408,Aiginia  |
|                                                 Bhubaneswar               |
|                                                                                         |
+---------------------------------------------------------+

JAVA LANGUAGE FIRST PROGRAM "HELLO WORLD"

Q-1-Write a java program to display following messages
                                      "Hello World"
INPUT :
        //NCM-New Coding Master :You Can Give Anything To The Class Name
public class NCM {

public static void main(String[] args) {
         
System.out.println("Hello World!");
      //It Will Print The Message
}

}
OUTPUT :
Hello World!