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

Java Program To Check Greater Between The Two Number: Import Class Public Static Void Throws Int Boolean New

The document contains code for several Java programs that demonstrate different programming concepts: 1. A program that checks if the first number entered is greater than the second number. 2. A program that demonstrates the use of pre and post operators on a variable. 3. A program that checks if a given number is a palindrome. 4. A program that uses a continue statement to skip outputting numbers in a certain range. 5. A program that determines if a character entered is a vowel, number, constant, or special character using a switch statement. 6. A program that calculates the sum of the digits in a given number.

Uploaded by

Ramu Ram
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
31 views5 pages

Java Program To Check Greater Between The Two Number: Import Class Public Static Void Throws Int Boolean New

The document contains code for several Java programs that demonstrate different programming concepts: 1. A program that checks if the first number entered is greater than the second number. 2. A program that demonstrates the use of pre and post operators on a variable. 3. A program that checks if a given number is a palindrome. 4. A program that uses a continue statement to skip outputting numbers in a certain range. 5. A program that determines if a character entered is a vowel, number, constant, or special character using a switch statement. 6. A program that calculates the sum of the digits in a given number.

Uploaded by

Ramu Ram
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

Java Program to check Greater

between the Two Number


1. import java.io.*;
2.
3. class optr{
4. public static void main(String args[]) throws IOException {
5. int a,b;
6. boolean c;
7.
8. DataInputStream din= new DataInputStream(System.in);
9.
10. System.out.println("Enter the 1st no.: ");
11. a=Integer.parseInt(din.readLine());
12. System.out.println("Enter the 2nd no.: ");
13. b=Integer.parseInt(din.readLine());
14.
15. c=a>b;
16. System.out.println("The result of the operation a>b is " +c+".");
17. }
18. }

Output of Above Java Program


Enter the 1st no.:
45
Enter the 2nd no.:
85
The result of the operation a>b is false.

Java Program to Demonstrate the


Use of Pre and Post Operator
view plainprint?

1. class prepost {
2. public static void main(String args[]){
3. int i=50;
4. System.out.println("The value is "+i +".");
5. System.out.println("The value of i++ is "+ i++ +".");
6. System.out.println("The value of ++i is "+ ++i +".");
7. System.out.println("The value of ++i is "+ ++i +".");
8. }
9. }

Output of Above Java Program:


The value is 50.
The value of i++ is 50.
The value of ++i is 52.
The value of ++i is 53.
Java Program to find that given
number is Palindrome or not
view plainprint?

1. import java.io.*;
2.
3. class palindrome {
4. public static void main(String [] args) throws IOException{
5. try{
6. BufferedReader obc=new BufferedReader (new InputStreamReader(System.in));
7. int r,n1,n2;
8. int rev=0;
9. System.out.println("Enter the number: ");
10. n1=Integer.parseInt(obc.readLine());
11. n2=n1;
12.
13. while(n1>0) {
14. r=n1%10;
15. rev=rev*10+r;
16. n1=n1/10;
17. }
18.
19. if(rev==n2) {
20. System.out.println("The number is Palindrome Number.");
21. } else {
22. System.out.println("The number is not a Palindrome Number.");
23. }
24. } catch(IOException e) {
25. System.out.println("Wrong number entered.");
26. }
27. }
28. }

Output of Above Java Program


Enter the number:
12321
The number is Palindrome Number.

Program to Demonstrate Skipping


using Continue
1. import java.io.*;
2.
3. class skip {
4. public static void main(String [] args) {
5. int a=1;
6. while(a<50) {
7. if(a>20 && a<=35) {
8. a++;
9. continue;
10. }
11.
12. System.out.print("\t"+a);
13. a++;
14. }
15. }
16. }

Output of Above Java Program


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 36 37 38 39 40 41 42 43 44 45 46
47 48 49

Program to find whether entered


character is a vowel, constant,
number or a special character
view plainprint?

1. import java.io.*;
2. class stch {
3. public static void main(String [] args) throws IOException {
4. char ch;
5. DataInputStream din=new DataInputStream(System.in);
6. System.out.println("Enter the character: ");
7. ch=(char)(din.read());
8. switch (ch) {
9. case 'a':
10. case 'e':
11. case 'i':
12. case 'o':
13. case 'u':
14. {
15. System.out.println("The character character is a Vowel.");
16. break;
17. }
18.
19. case '0':
20. case '1':
21. case '2':
22. case '3':
23. case '4':
24. case '5':
25. case '6':
26. case '7':
27. case '8':
28. case '9':
29.
30. {
31. System.out.println("The character entered is a Number.");
32. break;
33. }
34. case 'v':
35. case 'n':
36. case 't':
37. case 'b':
38. case 'r':
39. case 'f':
40. {
41. System.out.println("The character entered is a Special Character.");
42. break;
43. }
44. default:
45. {
46. System.out.println("The character entered is Constant.");
47. break;
48. }
49. }
50. }
51. }

Java Program to Calculate the Sum of


Digits of Given Number
1. import java.io.*;
2. class sumofdigit{
3. public static void main(String [] args) {
4. try{
5. BufferedReader din=new BufferedReader (new InputStreamReader(System.in));
6.
7. int n,r,s;
8. System.out.println("Please enter the number to find the sum of a digit: ");
9.
10. n=Integer.parseInt(din.readLine());
11. r=0;
12. s=0;
13.
14. while(n>0){
15. r=n%10;
16. s=s+r;
17. n=n/10;
18. }
19.
20. System.out.println("The sum of the digit is : " +s);
21. } catch(IOException e) {
22. System.out.println("Wrong Input");
23. }
24. }
25. }
26.

Output of sumofdigit Program:


Please enter the number to find the sum of a digit: 12345
The sum of the digit is : 15

You might also like