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

Class 12 JAVA Program

The document contains a series of Java programs demonstrating basic programming concepts such as displaying text, performing mathematical operations, using operators, and handling user input. Each program includes code snippets along with their expected outputs, covering topics like even/odd number identification, string length calculation, summing numbers, factorial computation, and palindrome checking. These examples serve as practical exercises for beginners learning Java programming.

Uploaded by

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

Class 12 JAVA Program

The document contains a series of Java programs demonstrating basic programming concepts such as displaying text, performing mathematical operations, using operators, and handling user input. Each program includes code snippets along with their expected outputs, covering topics like even/odd number identification, string length calculation, summing numbers, factorial computation, and palindrome checking. These examples serve as practical exercises for beginners learning Java programming.

Uploaded by

debbarmasuham526
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

WAP in Java to display any line of text

import [Link].*;
class Main
{
public static void main(String args[])
{
[Link]("Hello Welcome to Shishu Bihar H.S School");
}
}

OUTPUT
Hello Welcome to Shishu Bihar H.S School

2. WAP in Java to display value of a any number.

import [Link].*;

class Main
{
public static void main(String args[])
{
int a=10;
[Link]("Number available="+a);
}
}

Output

Number available=10

3. WAP in Java to perform different mathematical operations (addition, subtraction, multiplication


and Division) of two numbers.

import [Link].*;

class Main
{
public static void main(String args[])
{
int a=30,b=5,c;
[Link]("1st Number="+a);
[Link]("2nd Number="+b);
c=a+b;
[Link]("Addition ="+c);
c=a-b;
[Link]("Subtraction="+c);
c=a*b;
[Link]("Multiplication="+c);
c=a/b;
[Link]("Division="+c);
}
}

Output

1st Number=30
2nd Number=5
Addition =35
Subtraction=25
Multiplication=150
Division=6

4. WAP in java to illustrate the Increment operator.

import [Link].*;

class Main
{
public static void main(String args[])
{
int m=10,n=20;
[Link]("m="+m);
[Link]("n="+n);
[Link]("++m="+ ++m);
[Link]("n++"+ n++);
[Link]("m="+m);
[Link]("n="+n);

}
}

Output

m=10
n=20
++m=11
n++20
m=11
n=21

5. WAP in Java to input any number from user end and show the output.

import [Link].*;
import [Link].*;
class Main {
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("Insert any number");
int a=[Link]([Link]());
[Link]("Number="+a);
}
}

OUTPUT

10
Number=10

6. WAP in java to find whether a number is odd or even.

import [Link].*;
import [Link].*;
class Main {
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("Insert any number");
int a=[Link]([Link]());
if (a%2==0)
[Link]("Number="+a+" Its an even Number");
else
[Link]("Number="+a+" Its an odd Number");
}
}

OUTPUT
Insert any number
15
Number=15 Its an odd Number

7. WAP in Java to find the length of the string.

import [Link].*;
import [Link].*;
class Main {
public static void main(String[] args) throws IOException
{
int len;
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("Insert any line");
String a=[Link]();

[Link]("String="+a);
len=[Link]();
[Link]("Length of the string="+len);

}
}

Output

Insert any line


welcome to Java
String=welcome to Java
Length of the string=15

8. WAP In java to add numbers upto n terms.

import [Link].*;
import [Link].*;
class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("Insert any number between 1 to 10");
int i,count=0;
int a=[Link]([Link]());
[Link]("Number="+a);
for(i=1;i<=a;i++)
{
count=count+i;
}
[Link]();
[Link]("addition of n terms:="+count);
}
}

OUTPUT

Insert any number between 1 to 10


10
Number=10

addition of n terms:=55

9. WAP in Java to find the factorial of a number;

import [Link].*;
import [Link].*;
class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("Insert any number between 1 to 10");
int i,count=1;
int a=[Link]([Link]());
[Link]("Number="+a);
for(i=1;i<=a;i++)
{
count=count*i;
}
[Link]();
[Link]("Factorial of the number:="+count);
}
}

OUTPUT

Insert any number between 1 to 10


5
Number=5

Factorial of the number:=120

10. Write a program to find whether a number is palindrome.

import [Link].*;
import [Link].*;
class Main
{
public static void main (String args[])throws IOException
{
int num, reverse = 0, rem, temp;
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("Insert any number");
num=[Link]([Link]());
temp = num;
while (temp != 0)
{
rem = temp % 10;
reverse = reverse * 10 + rem;
temp /= 10;
};

if (num == reverse)
[Link] (num + " is Palindrome");
else
[Link] (num + " is not Palindrome");
}
}

Output
Insert any number
12021
12021 is Palindrome

You might also like