Skip to main content

Operator tutorials in Java

It is used to perform operations using operand, the operand can be variable, constant, or literals.
int a=10;  a is the variable,10 is the literals
System.out.println(100+200) ;  100 ,200 is called literals.
.....................................................................................................................................
The operator will be called by a symbol but defined as a method, for example, if we use + operator then + is the symbol but it has defined as  +() method
Operator +(param1)
{
}
Type of Operator:-
1) Unary Operator:-  This operator will work using a single operand.
1.1 Increment:-  increase current value by one
1.1.1  Post Increment:-       operand++
     First complete other operations (print, assign) then increase the value
       int a=5;
       int b;
       b=a++;
       System.out.println(a,",",b);

   The expected output is b=5 and a=6
1.1.2   Pre Increment:-        ++operand
      First increase value by one after that complete other operation
       int a=5;
       int b;
       b=++a;
       System.out.println(a,",",b);
class Incre
{
   public static void main(String args[])
   {
      int a=2,b=3;  
    
      System.out.println(a++  + "," + ++b );
   }
}

The expected output is  a=2 and b=4
Example of Increment |Decrement:-
class Incre
{
   public static void main(String args[])
   {
      int a=2,b=3; 
      b= a++ + a++ + a++ + a++;
  //   14   2      3        4        5           6

      System.out.println(a  + "," + b);
   }
}
class Incre
{
   public static void main(String args[])
   {
      int a=2,b=3;  
      b = ++a + a++ + ++a + a++;
  // 16      3     3      5    5  6
    System.out.println(a  + "," + b);
   }
}

1.2 Decrement
class Incre
{
   public static void main(String args[])
   {
      int a=12,b=3; 
      b = --a + a-- + --a + a--;
   //  40      11    11     9   9  8
      System.out.println(a  + "," + b);

   }
}

2) Binary  Operator:-
It requires a minimum of two operands to perform the operation.
2.1 ) Arithmetic Operator:-  +,  -,  *,   /,   %
2.2)  Conditional Operator:-   <  , >, <=,  >=
2.3)  Comparison Operator:-  
2.,3.1  Data Comparision Operator  ==
2.3.2   Address Comparaision Operator equals():-
 class Eqldemo
{
public static void main(String args[])
{
   String s ="hello";
   String s1 = new String("hello");
   if(s.equals(s1))
   {
      System.out.println("equall");
   }
  else
   {
       System.out.println("not equall");
   }
}
}
2.4)  Assignment Operator
       2.4.1)  Simple     =
       2.4.2)  Complex  Assignment or Shorthand Operator 
          +=,     -=   ,    *=,     /= ,     %=
         a+=7  or a=a+7
         a-=3   or a=a-3
 class Eqldemo
{
public static void main(String args[])
{
   int a=5;
   a+=9;  //14
   a-=3;  //11
   a*=12; //132
   a/=17; //7
   a%=3;   //1
   a*=23;  //23
   System.out.println(a);  
}
}
2.5) Logical Operator:-    &&, ||, !
     &&:-  it returns true when all conditions will be true
      ||:-       it returns true when a particular condition will be true
      !:-        it is the opposite of a true statement and converted the result into a false statement
      a=9   
    a>2 && a<5
     a>2 or a<5
Assignment:-
1)  WAP to convert Decimal to binary and binary to decimal
2)  WAP to perform addition of number without using + operator?
3) Ternary Operator:-
It is used to solve condition-based problems using a single-line statement. Ternary operators contain a minimum of three operators to solve statements.
res = (condition)? true : false;
WAP to check that the entered number is even or odd using the ternary operator
class CheckEvenOdd
{
    public static void main(String args[])
    {
        int num=4;
        String s = (num%2==0)?"Even":"Odd";
        System.out.println(s);            
    }
}
class Checkgreater
{
   public static void main(String args[])
   {
      int a=2,b=5;
      String s = (a>b)?"a is greater":"b is greater";
      System.out.println(s);
   }
}

WAP to check vowel and consonant?
WAP to check Leap Year?
The solution to this Program
import java.util.Scanner;
class CheckLeapYear
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int year;
        System.out.println("Enter year");
        year = sc.nextInt();
        String s = (year%400==0) || (year%100!=0 && year%4==0)? "leap year": "not a 
leap year";
       System.out.println(s);        
   }
}
Check Leap Year Without using Scanner class?
import java.io.IOException;
class CheckLeapYear
{
    public static void main(String args[]) throws IOException
    {       
        char arr[] = new char[4];
        int year;
        System.out.println("Enter year");
        for(int i=0;i<4;i++)
        {
           arr[i]= (char)System.in.read();
        }
        String s = new String(arr); // char array to String
        year =Integer.parseInt(s);  //String to int
        String s = (year%400==0) || (year%100!=0 && year%4==0)? "leap year": "not a 

leap year";
       System.out.println(s);        
   }
}
WAP to check that today is Sunday or not?
Solution of This Program:-
import java.util.Scanner;
class Weekday
{
   public static void main(String args[])
   {
      String day;
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter day");
      day = sc.next();
      String res = day.equals("sunday") || day.equals("Sunday")?"Today is sunday": 

"Other day";
      System.out.println(res);
   }
}
WAP to check that number is divisible by 3 and 5 both or not?
WAP to check that char is numeric or alphabets?
Solution of this program:-
import java.util.Scanner;
class CheckNumeric
{
public static void main(String args[])
{
     Scanner sc = new Scanner(System.in);
     char ch;
     System.out.println("Enter char");
     ch = sc.next().charAt(0);   //charAt() return the char based on index
     int asc = ch;   // return ascii code
     String s = (asc>=48 && asc<=57)? "Numeric" : "Alphabets";
     System.out.println(s);      
}
 WAP to check the greatest number?
hint:- 
int a=2,b=45,c=30;
String s = (a>b && a>c)? "a is greatest":(b>c)?"b is greatest":"c is greatest";

Comments

  1. import java.util.Scanner;
    class Checknumber
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    char ch;
    System.out.println("Enter char");
    ch=sc.next().charAt(0); // "h"
    String s = (ch>=48 && ch<=57)?"numeric":"other";
    System.out.println(s);


    }


    }

    ReplyDelete
  2. Program of Greatest Number Solved in class by me import java.util.Scanner;
    class Checkgrt
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    int a=1000,b=2000,c=3000;
    String s = (a>b && a>c)?"a is greatest":(b>c?" b is greatest":" c is

    greatest");
    System.out.println(s);


    }


    }

    ReplyDelete
  3. class Revv
    {
    public static void main(String args[])
    {
    int a=12345;
    int d1,d2,d3,d4,d5,rev,temp;
    temp=a;
    d5=a%10;
    a=a/10;
    d4=a%10;
    a=a/10;
    d3=a%10;
    a=a/10;
    d2=a%10;
    a=a/10;
    d1=a;
    a=temp;
    rev=d1*10000+d4*1000+d3*100+d2*10+d5;
    System.out.println("The reverse of "+a+" without changing the first and the last digit is: "+rev);
    }
    }

    ReplyDelete
  4. class Vowel
    {
    public static void main(String args[])
    {
    char ch='m';
    int i=0;
    switch(ch)
    {
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
    case 'A':
    case 'E':
    case 'I':
    case 'O':
    case 'U':i++;
    }
    if(i==1)
    {
    System.out.println(ch+" is a Vowel");
    }
    else
    {
    if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
    {
    System.out.println(ch+" is a Consonent");
    }
    else
    {
    System.out.println(ch+" is not an alphabet");
    }
    }
    }
    }

    ReplyDelete
  5. class Leap
    {
    public static void main(String args[])
    {
    int year=1900;
    if(((year%4==0)&&(year%100!=0))||(year%400==0))
    {
    System.out.println("Leap Year");
    }
    else
    {
    System.out.println("Not a Leap Year");
    }
    }
    }

    ReplyDelete
  6. class Sunday
    {
    public static void main(String args[])
    {
    String s= "monday";
    if(s=="sunday")
    {
    System.out.println("Weekend yay!");
    }
    else
    {
    System.out.println("Not a holiday!");
    }
    }
    }

    ReplyDelete
  7. class Div
    {
    public static void main(String args[])
    {
    int d=15;
    String s=((d%3==0)&&(d%5==0))?"Yes":"No";
    System.out.println(s);
    }
    }

    ReplyDelete
  8. class Grt
    {
    public static void main(String args[])
    {
    int x=4,y=1,z=3;
    String s=(x>y&&x>z)?"x is greatest":(y>z)?"y is greatest":"z is greatest";
    System.out.println(s);
    }
    }

    ReplyDelete
  9. class Numalph
    {
    public static void main(String args[])
    {
    char c='4';
    String s=(c>=48&&c<=57)?"Numeric":"Alphabet";
    System.out.println(s);
    }
    }

    ReplyDelete
  10. import java.util.Scanner;
    class divisible
    {
    public static void main(String[]arg)
    {
    int a;
    Scanner sc=new Scanner(System.in);
    System.out.println("enter the number");
    a=sc.nextInt();

    if((a%3==0)&&(a%5==0))
    {
    System.out.println("this value is divisible by 3 and 5");
    }
    else
    {
    System.out.println("value is not divisible");
    }

    }
    }

    ReplyDelete
  11. class greatno
    {
    public static void main(String[]arg)
    {
    int a=2,b=45,c=30;

    String s=(a>b&&a>c)?"a is greatest":(b>c)?"b is greatest":"c is greatest";

    System.out.println(s);
    }
    }

    ReplyDelete
  12. import java.util.Scanner;

    class x1
    {
    public static void main(String[]args)
    {

    Scanner sc=new Scanner(System.in);

    System.out.println("enter the value of c");
    char c=sc.next().charAt(0);

    if((c>='a' && c<='z')|| (c >= 'A' && c<='Z'))
    {
    System.out.println("this is alphabales");
    }
    else
    {
    System.out.println("other");
    }
    }
    }

    ReplyDelete
  13. WAP to check the greatest number

    class Tren
    {
    public static void main(String args[])
    {
    int a=220, b=44, c=888;
    String s=(a>b&& a>c)?"a is greatest":(b>c)?"b is greatest": "c is greatest";
    System.out.println(s);
    }
    }

    ReplyDelete
  14. class Divis
    {
    public static void main(String[]args)
    {
    int a=30;
    String s=((a%3==0) && (a%5==0))?"yes":"no";
    System.out.println(s);
    }
    }

    ReplyDelete
  15. class Reverse
    {
    public static void main(String args[])
    {
    int a=12345,d1,d2,d3,d4,d5,rev;

    d5=a%10;
    a=a/10;
    d4=a%10;
    a=a/10;
    d3=a%10;
    a=a/10;
    d2=a%10;
    a=a/10;
    d1=a;

    rev=d1*10000+d4*1000+d3*100+d2*10+d5;
    System.out.println(rev);
    }
    }

    ReplyDelete
  16. class Reverse
    {
    public static void main(String args[])
    {
    int a=12345,d1,d2,d3,d4,d5,rev;

    d5=a%10;
    a=a/10;
    d4=a%10;
    a=a/10;
    d3=a%10;
    a=a/10;
    d2=a%10;
    a=a/10;
    d1=a%10;
    a=a/10;

    rev=d1*10000+d4*1000+d3*100+d2*10+d5;
    System.out.println(rev);
    }
    }

    ReplyDelete
  17. class Leapyear
    {
    public static void main(String[]args)
    {
    int a=1987;
    if (((a%4==0) && (a%100!=0))|| (a%400==0))
    {
    System.out.println("leap year");
    }
    else
    {
    System.out.println("no leap year");

    }
    }
    }

    ReplyDelete
  18. Q : - Example of Post Increment Operator ??
    Solution:-
    class Incre
    {
    public static void main(String args[])
    {
    int a=5,b=15;
    b= a++ + a++ + a++ + a++;
    System.out.println(a + "," + b);
    }
    }

    ReplyDelete
  19. Q:- Example of decrement operator ??
    Solution:-
    class Decre
    {
    public static void main(String args[])
    {
    int a=5,b=15;
    b = --a + a-- + --a + a--;
    System.out.println(a + "," + b);
    }
    }

    ReplyDelete
  20. Q:- Check the entered number is Even or Odd using the ternary operator ??
    Solution:-

    class EvenOdd
    {
    public static void main(String args[])
    {
    int num=20;
    String s = (num%2==0)?"Even":"Odd";
    System.out.println(s);
    }
    }

    ReplyDelete
  21. Q:- Check the Greater numberamong two Number's using the ternary operator ??
    Solution:-

    class Checkgreater
    {
    public static void main(String args[])
    {
    int a=2,b=5;
    String s = (a>b)?"a is greater":"b is greater";
    System.out.println(s);
    }
    }

    ReplyDelete
  22. Q:- WAP to check Leap Year ??
    Solution:-
    class Leap
    {
    public static void main(String args[])
    {
    int year=2020;
    if(((year%4==0)&&(year%100!=0))||(year%400==0))
    {
    System.out.println("It is Leap Year.");
    }
    else
    {
    System.out.println("It is not a Leap Year.");
    }
    }
    }

    ReplyDelete
  23. Q:- WAP to check the the given character is Vowel or Consonent ??
    Solution:-
    class Vowel
    {
    public static void main(String args[])
    {
    char ch='o';
    if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
    {
    System.out.println("It is Vowel.");
    }
    else
    {
    System.out.println("It is Consonent.");
    }
    }
    }

    ReplyDelete
  24. Q:- WAP to check that today is Sunday or not ??
    Solution:-
    class Sunday
    {
    public static void main(String args[])
    {
    String a= "sunday";
    if(a=="friday")
    {
    System.out.println("It's Sunday Today.");
    }
    else
    {
    System.out.println("Today it's not a Sunday !!");
    }
    }
    }

    ReplyDelete
  25. Q:-WAP to reverse a five-digit number where the first digit and last digit will be the same ??
    Solution:-
    class Rever
    {
    public static void main(String args[])
    {
    int a=12345;
    int a1,a2,a3,a4,a5,rev,temp;
    temp=a;
    a5=a%10;
    a=a/10;
    a4=a%10;
    a=a/10;
    a3=a%10;
    a=a/10;
    a2=a%10;
    a=a/10;
    a1=a;
    a=temp;
    rev=d1*10000+d4*1000+d3*100+d2*10+d5;
    System.out.println("The reverse of "+a+" without changing the first and the last digit is: "+rev);
    }
    }

    ReplyDelete
  26. Q:-WAP to check that number is divisible by 3 and 5 both or not ??
    Solution:-
    class Divisible
    {
    public static void main(String args[])
    {
    int a=2000;
    if((a%3==0)&&(a%5==0))
    {
    System.out.println("It is Divisible by 3 and 5.");
    }
    else
    {
    System.out.println("It is not Divisible by 3 and 5.");
    }
    }
    }

    ReplyDelete
  27. Solution of check divisibility by 3 and 5
    class CheckVC
    {
    public static void main(String args[])
    {
    int num=211;
    String s = (num%3==0 && num%5==0)? "divisible by 3 and 5 both":(num

    %3==0?"divisible by 3":(num%5==0?"divisible by 5":"not divisible by any"));
    System.out.println(s);

    }


    }

    ReplyDelete
  28. class vowel
    {
    public static void main(String args[])
    {
    char ch='B';
    // char 'a','e','i','o','u';
    // if(o=='a'|| o=='e'|| o==i|| o=='o'|| o=='u')
    if(ch=='a'|| ch=='e'|| ch=='i'|| ch=='o'|| ch=='u')
    {
    System.out.println("it is vowel");
    }
    else
    {
    System.out.println("it is constant ");
    }
    }
    }

    ReplyDelete
  29. class Leap
    {
    public static void main(String args[])
    {
    int year=2000;
    if((year%4==0)&&(year%100!=0)&&(year%400==0))
    {
    System.out.println("it is leap year");
    }
    else
    {
    System.out.println("it is not a leap year");
    }
    }
    }

    ReplyDelete
  30. class sunday
    {
    public static void main(String args[])
    {
    String a="Monday";
    if(a=="monday")
    {
    System.out.println("today is sunday");
    }
    else
    {
    System.out.println("today is not a sunday");

    }
    }
    }

    ReplyDelete
  31. class number
    {
    public static void main(String args[])
    {
    int x=12100;
    if((x%3==0)&&(x%5==0))
    {
    System.out.println(" value is divisible ");
    }
    else
    {
    System.out.println(""value is not divisible");
    }
    }
    }

    ReplyDelete
  32. class alphabets
    {
    public static void main(String args[])
    {
    char ch='g';

    String s=(ch>='a' && ch<='c')||(ch>='E'&& ch<='D')? "ch is an alphabets":"ch is not alphabets";

    System.out.println(s);
    }

    }

    ReplyDelete
  33. class greatest
    {
    public static void main(String args[])
    {
    int a=2,b=3,c=4;

    String s=(a>b && a>c)? "a is greatest":(b>c)?"b is greatest":"c is greatest";
    System.out.println(s);
    }
    }

    ReplyDelete
  34. class add
    {
    public static void main(String args[])
    {
    int x=12,y=13;
    int z=x-(-y);
    System.out.println("z="+z);
    }
    }

    ReplyDelete
  35. class Vowel
    {
    public static void main(String arg[])
    {

    char ch='a';

    String s=(ch=='a'|| ch=='b'|| ch=='e'|| ch=='i'|| ch=='o'|| ch=='u')?"vowel":"not a vowel";
    System.out.println(s);
    }
    }

    ReplyDelete
  36. class Div
    {
    public static void main(String arg[])
    {
    int n=25;
    String s=(n%3==0 && n%5==0)?"no.is divisible":"nt divisible";
    System.out.println(s);
    }
    }

    ReplyDelete
  37. class Divide
    {
    public static void main(String[]arg)
    {
    int a=12;


    if((a%3==0)&&(a%5==0))
    {
    System.out.println("this value is divisible by 3 and 5");
    }
    else
    {
    System.out.println("value is not divisible");
    }

    }
    }

    ReplyDelete
  38. class AddWplus
    {
    public static void main(String args[])
    {
    int a=12,b=13;
    int c=a-(-b);
    System.out.println("sum="+c);
    }
    }

    ReplyDelete
  39. /* Wap to perform addition of number without using + operator */
    import java.util.*;
    class Basic
    {
    static public void main(String ar[])
    {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    int y=sc.nextInt();
    x+=y;
    System.out.println("Sum+ "+x);
    }
    }

    ReplyDelete
  40. /* Wap to check that the entered number is even or odd using the ternary operator */

    import java.util.*;
    class Basic
    {
    static public void main(String ar[])
    {
    Scanner sc=new Scanner(System.in);
    int x=sc.nextInt();
    String check=(x%2==0)?"Even":"Odd";
    System.out.println("Given No.is= "+check);
    }
    }

    ReplyDelete
  41. // Wap to check vowel and consonent

    import java.util.*;
    class Basic

    {
    static public void main(String ar[])
    {
    Scanner sc=new Scanner(System.in);
    char s=sc.next().charAt(0);


    if(s=='a'||s=='e'||s=='i'||s=='o'||s=='u')
    {
    System.out.println("given char is Vowel");
    }
    else
    {
    System.out.println("Given char is Consonant");
    }

    }
    }

    ReplyDelete
  42. Q.) WAP to perform addition of number without using + operator?


    class PlusOperator
    {
    public static void main(String[] args)
    {
    int a=10,b=20;
    //a+=b;
    a=a-(-b);
    System.out.println("Sum:"+a);

    }
    }

    ReplyDelete
  43. wap to convert decimal to binary
    //Abhishek chauhan


    import java.util.*;

    public class BinaryToDecimal
    {
    public static void main(String args[])
    {
    int num;
    Scanner sc=new Scanner(System.in);

    System.out.print("Enter any integer number: ");
    num = sc.nextInt();

    String str=Integer.toBinaryString(num);
    System.out.println("Binary number is : "+ str);
    }
    }

    ReplyDelete
  44. /// WAP to perform addition of number without using + operator?

    //Abhishek chauhan
    import java.util.Scanner;

    public class SumOfTwoNumbersWithOutPlusOperator {

    public static void main(String[] args) {


    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter First Number : ");
    int input1 = scanner.nextInt();
    System.out.print("Enter Second Number : ");
    int input2 = scanner.nextInt();


    int output = input1 -(- input2);

    System.out.println("without operator(" + input1 + ", " + input2 + ") = " + output);

    }

    }




    //output=Enter First Number : 20
    Enter Second Number : 5
    without operator(20, 5) = 25


    ReplyDelete
  45. //WAP to check that the entered number is even or odd using the ternary operator



    class CheckEvenNumberTurnery {
    public static void main( String args[] ) {
    int number = 3;
    String msg = (number % 2 == 0) ? " The number is even!" : " The number is odd!";
    System. out. println(msg);
    }
    }

    //output

    The number is odd!

    ReplyDelete
  46. // Abhishek chauuhan
    // divisible by 3 and 5 for a given number


    class CheckNo
    {


    static void result(int N)
    {

    for (int num = 0; num < N; num++)
    {

    if (num % 3 == 0 && num % 5 == 0)
    System.out.print(num + " ");
    }
    }


    public static void main(String []args)
    {

    int N = 100;


    result(N);
    }
    }

    class CheckNo
    {

    // Result function with N
    static void result(int N)
    {
    // iterate from 0 to N
    for (int num = 0; num < N; num++)
    {
    // Short-circuit operator is used
    if (num % 3 == 0 && num % 5 == 0)
    System.out.print(num + " ");
    }
    }

    // Driver code
    public static void main(String []args)
    {
    // input goes here
    int N = 100;

    // Calling function
    result(N);
    }
    }

    ReplyDelete
  47. WAP to perform addition of number without using + operator?
    // Abhishek chauhan

    import java.util.Scanner;

    public class SumOfTwoNumbersWithOutPlusOperator {

    public static void main(String[] args) {

    // reading input from user
    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter First Number : ");
    int input1 = scanner.nextInt();
    System.out.print("Enter Second Number : ");
    int input2 = scanner.nextInt();

    // summing two numbers
    int output = input1 -(- input2);

    System.out.println("without operator(" + input1 + ", " + input2 + ") = " + output);

    }
    }

    ReplyDelete
  48. // WAP to convert Decimal to binary and binary to decimal
    import java.util.*;
    class BinaryToDecimal
    {
    public static void main(String... args)
    {
    int num,rem,i=1,bin=0,j=0,n;
    double dec=0;
    Scanner sc= new Scanner(System.in);
    System.out.println("Enter 1 for Decmial to Binary conversion");
    System.out.println("Enter 2 for Binary to Decimal conversion");
    System.out.println("Enter");
    n=sc.nextInt();
    if(n==1)
    {
    System.out.println("Enter Decimal number");
    num=sc.nextInt();
    while(num!=0)
    {
    rem=num%2;
    num=num/2;
    bin=bin+rem*i;
    i=i*10;
    }
    System.out.println("Binary number is"+bin);
    }
    if(n==2)
    {
    System.out.println("Enter Binary number");
    num=sc.nextInt();
    while(num!=0)
    {
    rem=num%10;
    num/=10;
    dec=dec+rem*Math.pow(2,j);
    j++;
    }
    System.out.println("Decimal number is"+dec);
    }
    else
    {
    System.out.println("Invalid Selection");
    }

    }
    }

    ReplyDelete
  49. //WAP to perform addition of number without using + operator?

    class AddWithoutPlusOperator
    {
    public static void main(String...args)
    {
    int num1=2,num2=2;
    num2=-num2;
    System.out.println(num1-num2);
    }
    }

    ReplyDelete
  50. WAP to convert Decimal to binary
    Program:

    public class Decimal_to_binary {

    public static void main(String[] args) {

    int num=38,temp;
    String binary=" ";
    while(num>1) {
    temp=num%2;
    binary=(String.valueOf(temp)).concat(binary);

    num=num/2;
    if(num==1) {
    binary=(String.valueOf(num)).concat(binary);
    System.out.println(binary);
    }

    }




    }

    }

    ReplyDelete
  51. //WAP to check vowel and consonant?
    import java.util.Scanner;
    class CheckVowelConsonant
    {
    public static void main(String... args)
    {
    char ch;
    Scanner sc=new Scanner(System.in);
    ch = sc.next().charAt(0);
    if(ch=='A'|| ch=='E'|| ch=='I'|| ch=='O' || ch=='U' || ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' )
    System.out.println(ch+" is Vowel");
    else
    System.out.println(ch+" is consonant");
    }
    }

    ReplyDelete
  52. WAP to convert Decimal to binary
    public class Decimal_to_binary {

    public static void main(String[] args) {

    int num=38,temp;
    String binary=" ";
    while(num>1) {
    temp=num%2;
    binary=(String.valueOf(temp)).concat(binary);

    num=num/2;
    if(num==1) {
    binary=(String.valueOf(num)).concat(binary);
    System.out.println(binary);
    }

    }




    }

    }

    ReplyDelete
  53. AKSHAY
    class Addi

    {
    public static void main(String...args)
    {
    int a=10,b=10;

    System.out.println(a-(-b));
    }
    }

    ReplyDelete
  54. import java.util.*;
    class Divi
    {
    public static void main(String...args)
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter the number");
    int n=sc.nextInt();
    String s=(n%3 == 0) && (n%5 == 0) ? "is divisible by both" : "not divisible";
    System.out.println(s);
    }
    }

    ReplyDelete
  55. class Greatest
    {
    public static void main(String...args)
    {
    int a=10,b=20,c=30;
    String s = (a>b && a>c)? "a is greatest":(b>c)?"b is greatest":"c is greatest";
    System.out.println(s);
    }
    }

    ReplyDelete
  56. // Q)WAP to check Leap Year?
    class LeapYear

    {
    public static void main(String args[])
    {
    int year=2020;
    String s=(year%400==0)||(year%4==0 && year%100!=0)?"leap year":"not leap year";
    System.out.println(s);
    }
    }

    ReplyDelete
  57. // WAP to perform addition of number without using + operator?
    import java.util.Scanner;
    class Addition
    {
    public static void main (String args[])
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("enter a");
    int a =sc.nextInt();
    System.out.println("enter b");
    int b =sc.nextInt();
    System.out.println(a-(-b));
    }
    }

    ReplyDelete
  58. WAP to convert Decimal to binary and binary to decimal
    Program:

    public class Decimal_to_binary {

    public static void main(String[] args) {

    int num=38,temp;
    String binary=" ";
    // Decimal to binary
    while(num>1) {
    temp=num%2;
    binary=(String.valueOf(temp)).concat(binary);

    num=num/2;
    if(num==1) {
    binary=(String.valueOf(num)).concat(binary);
    System.out.println(binary);
    }

    }
    temp=0;
    int count=1,decimal=0;
    // binary to decimal
    num=1001101;
    while(num>0) {
    temp=num%2;
    decimal=decimal+temp*count;
    count=count*2;
    num=num/10;

    }
    System.out.println("decimal number - "+decimal);





    }

    }

    ReplyDelete
  59. WAP to perform addition of number without using + operator
    Program:
    class Addition_ {
    public static void main(String[] args) {
    int a=5,b=3;
    while(b>0) {
    a++;
    b--;
    }
    System.out.print(a);

    }
    }

    ReplyDelete
  60. WAP to check vowel and consonant?
    Program:

    class Vowel_consonant {
    public static void main(String[] args) {
    char ch='t';
    String str=" ";
    str = (ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')?"vowel":"consonant";
    System.out.println(ch+" is a "+str);
    }
    }

    ReplyDelete
  61. //WAP to check vowel and consonant?
    import java.util.Scanner;
    class Vowel
    {
    public static void main (String args[])
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("enter char");
    char ch=sc.next().charAt(0);
    if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
    {
    System.out.println("It is vowel.");
    }
    else
    {
    System.out.println("It is consonent");
    }
    }
    }

    ReplyDelete
  62. //WAP to check that today is Sunday or not?
    import java.util.Scanner;
    class Sunday
    {
    public static void main(String args[])
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("enter day");
    String s=sc.next();
    if(s=="sunday")
    {
    System.out.println("It is Sunday ");
    }
    else
    {
    System.out.println("No Sunday");
    }
    }
    }

    ReplyDelete


  63. import java.util.Scanner;
    class Check
    {
    public static void main(String args[])
    {
    String s1,s2="sunday";
    Scanner sc=new Scanner(System.in);
    System.out.println("enter any day");
    s1=sc.nextLine();

    if(s1==s2)
    {
    System.out.println("today is sunday");
    }
    else
    {

    System.out.println("not sunday");
    }


    }
    }

    ReplyDelete
  64. //WAP to check that number is divisible by 3 and 5 both or not?
    import java.util.Scanner;
    class Number
    {
    public static void main(String args[])
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("enter x");
    int x=sc.nextInt();
    if((x%3==0) && (x%5==0))
    {
    System.out.println("value is divisible");
    }
    else
    {
    System.out.println("value is not divisible");
    }
    }
    }

    ReplyDelete
  65. import java.util.Scanner;
    class ConVo
    {
    public static void main(String args[])
    {
    char ch;
    Scanner sc=new Scanner(System.in);
    System.out.println("enter any character");
    ch=sc.next().charAt(0);
    if(ch=='a' ||ch=='e' || ch=='i' || ch=='o' || ch=='u')
    {
    System.out.println("this is a vowel " +ch);

    }
    else
    {
    System.out.println("this is a consonent " +ch);
    }
    }

    }

    ReplyDelete
  66. // WAP to check the greatest number?
    class Greatestnum
    {
    public static void main (String args[])
    {
    int a=20,b=15,c=30;

    String s = (a>b && a>c)? "a is greatest":(b>c)?"b is greatest":"c is greatest";
    System.out.println(s);
    }
    }

    ReplyDelete
  67. /*Divisible by 3 and 5 both or not*/
    class Divisibility
    {
    public static void main(String args[])
    {
    int num=15;
    String s=(num%3==0 && num%5==0)?"Divisible by both":"Not divisible by both";
    System.out.println(s);
    }
    }

    ReplyDelete
  68. -WAP to check character is vowel or consonent?

    import java.util.Scanner;
    class Vowel
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter Character");
    char ch=sc.next().charAt(0);
    String s=(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')? "vowel": "consonent";
    System.out.println(s);
    }
    }

    ReplyDelete
  69. -WAP to check char is numeric or alphabetic

    import java.util.Scanner;
    class Numeric
    {
    public static void main(String args[])
    {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter a character");
    char ch=sc.next().charAt(0);
    String s=((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))? "Alphabetic" : "Numeric";
    System.out.println(s);
    }

    ReplyDelete
  70. -WAP to convert decimal to binary

    import java.util.Scanner;
    class DectoBin
    {
    public static void main(String args[])
    {
    int n, r;
    String s = "";
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter decimal number ");
    n = sc.nextInt();
    while(n>0)
    {
    r = n%2;
    s = s+" "+r;
    n = n/2;
    }
    System.out.println("Binary number: "+s);
    }
    }

    ReplyDelete
  71. //Q)WAP to check that number is divisible by 3 and 5 both or not?

    class Divisible
    {
    public static void main(String args[])
    {

    int num=40;
    if(num%3==0&& num%5==0)
    System.out.println(num+" :is divisible by 3 and 5");
    else
    System.out.println(num+" is not divisible by 3 and 5");


    }
    }

    ReplyDelete
  72. //Q)WAP to check that number is divisible by 3 and 5 both or not using Ternary

    class Divisible
    {
    public static void main(String args[])
    {

    int num=15;
    String s=(num%3==0&& num%5==0)?"divisible by 3 And 5":"not Divisible by 3 and 5 ";
    System.out.println(s);

    }
    }

    ReplyDelete
  73. //wap to calculate leap year
    class Leap
    {
    public static void main(String abc[])
    {
    int year=2021;
    String s=(year%400==0||(year%100==0&&year%4==0))?"leapyear":"not a leap year";
    System.out.println(s);
    }
    }

    ReplyDelete
  74. //WAP to check that char is numeric or alphabets?
    import java.util.Scanner;
    class Vowel
    {
    public static void main(String abc[])
    {
    char x;
    Scanner sc= new Scanner(System.in);
    System.out.println("enter character");
    x= sc.next().charAt(0);
    String s=(x=='a'||x=='e'||x=='i'||x=='o'||x=='u')?"vowel":"consonent";
    System.out.println(s);
    }
    }

    ReplyDelete
  75. //WAP to check that char is numeric or alphabets?
    import java.util.Scanner;
    class Vowel
    {
    public static void main(String abc[])
    {
    char x;
    Scanner sc= new Scanner(System.in);
    System.out.println("enter character");
    x= sc.next().charAt(0);
    String s=(x=='a'||x=='e'||x=='i'||x=='o'||x=='u')?"vowel":"consonent";
    System.out.println(s);
    }
    }

    ReplyDelete
  76. //WAP to check that number is divisible by 3 and 5 both or not?
    class Divisible
    {
    public static void main(String abc[])
    {
    int a=35;
    String s=(a%5==0&&a%3==0)?"divisible by both":"not divisible by both";
    System.out.println(s);
    }
    }

    ReplyDelete
  77. // WAP to check that today is Sunday or not ??
    class A
    {
    public static void main(String abc[])
    {
    String a=sunday;
    String s=(a==sunday&&(a==monday||a==tuesday||a==wednesday||a==thursday||a==friday||a==saturdayS))?"It's Sunday Today":"It's Sunday Today." ";
    System.out.println(s);
    }
    }

    ReplyDelete
  78. WAP to convert Decimal to binary

    class Decimal
    {
    public static void main(String abc[])
    {
    int num=21,a;
    String binary=" ";
    while(num>1)
    {
    a=num%2;
    binary= (String.valueOf(a)).concat(binary);
    num=num/2;
    if(num==1)
    {
    binary= (String.valueOf(num)).concat(binary);
    System.out.println(binary);
    }
    }
    }
    }

    ReplyDelete

  79. Ankita Verma

    class Add1
    {
    public static void main(String args[])
    {
    int y=4;
    int z=-8;
    y-=z;

    System.out.println("value of=" +y);
    }
    }

    ReplyDelete

  80. Ankita Verma

    class AlpaNum
    {
    public static void main(String args[])
    {

    char ch='55';

    String s=(ch>=48 && ch<=57)&&(ch>=91 && ch<123)||(ch>=65 && ch<=90)?"numeric":"alphabets";

    System.out.println(s);
    }
    }

    ReplyDelete
  81. Ankita Verma

    class Character
    {
    public static void main(String args[])
    {
    char ch='n';
    int i=0;
    switch(ch)
    {
    case'a':
    case'A':

    case'e':
    case'E':

    case'i':
    case'I':

    case'o':
    case'O':

    case'u':
    case'U':
    i++;
    }
    if(i==1)
    {

    System.out.println(ch+ "vowel");
    }
    else
    {
    System.out.println(ch+ "consonent");
    }
    }
    }

    ReplyDelete
  82. Ankita Verma

    import java.util.Scanner;
    class Decbin
    {
    public static void main(String args[])
    {
    Scanner sc= new Scanner(System.in);
    System.out.println("Enter the Binary No.=");
    int n= sc.nextInt();

    int d=0;
    int t=n;
    int i=0;
    while(t>0)
    {
    int r=t%10;
    t=t/10;
    d=d + r *(int)Math.pow(2,i++);
    }
    System.out.println("Decimal No.is = " +n+" is " +d);
    }
    }

    ReplyDelete

  83. Ankita Verma

    import java.util.Scanner;
    class BinDec
    {
    public static void main(String args[])
    {
    Scanner sc= new Scanner(System.in);
    System.out.println("Enter the Decimal No.=");
    int n= sc.nextInt();

    String b="";
    int t=n;
    while(t>0)
    {
    int r=t%2;
    t=t/2;
    b=b+r;
    }
    System.out.println("Binary no.of" +n+ " is " +b);
    }
    }

    ReplyDelete
  84. Ankita Verma
    class Div
    {
    public static void main(String args[])
    {

    int a=27;

    String s=(a%3==0)&&(a%5==0)?"divisible both":"not divisible both";

    System.out.println(s);
    }
    }

    ReplyDelete


  85. Ankita Verma

    class Greatest
    {
    public static void main(String arg[])
    {
    int a=2,b=45,c=30;
    String s=(a>b&&a>c)?"a is greatest":(b>c)?"b is greatest":"c is greatest";
    System.out.println(s);
    }
    }

    ReplyDelete
  86. Ankita Verma
    class Greatest
    {
    public static void main(String arg[])
    {
    int a=2,b=45,c=30;
    String s=(a>b&&a>c)?"a is greatest":(b>c)?"b is greatest":"c is greatest";
    System.out.println(s);
    }
    }

    ReplyDelete
  87. Ankita Verma
    class Leapyear
    {
    public static void main(String args[])
    {

    int year=1991;

    String s=(year%4==0)||(year%100!=0)||(year%400==0)?"Leap year":"not a Leap year";

    System.out.println(s);
    }
    }

    ReplyDelete

  88. Ankita Verma
    class Max
    {
    public static void main(String args[])
    {
    int x=457;
    int a=x%10;
    x=x/10;
    int b=x%10;
    x=x/10;
    int c=x%10;
    x=x/10;

    int max=0;
    if(max<a)
    {
    max=a;

    System.out.println(max);
    }
    }
    }

    ReplyDelete
  89. Ankita Verma

    class Weak
    {
    public static void main(String args[])
    {
    char ch='7';

    switch(ch)
    {
    case'1':
    System.out.println("Today is Monday");
    break;

    case'2':
    System.out.println("Today is Tuesday");
    break;

    case'3':
    System.out.println("Today is Wednesday");
    break;

    case'4':
    System.out.println("Today is Thursday");
    break;

    case'5':
    System.out.println("Today is Friday");
    break;

    case'6':
    System.out.println("Today is Saturday");
    break;

    case'7':
    System.out.println("Today is Sunday");
    break;

    default:
    System.out.println("Invalidday");
    }
    }
    }

    ReplyDelete
  90. package sundayornot;

    public class SundayOrNot {

    public static void main(String[] args) {
    String s= "Monday";
    String res=(s=="Monday"||s=="Tuesday"||s=="Wednesday"||s=="Thursday"||s=="Friday"||
    s=="Saturday")?"day is not Sunday":"day is Sunday";
    System.out.println(res);
    }

    }

    ReplyDelete
  91. public class Greatestno {
    public static void main(String args[])
    {
    int a=89,b=45,c=50;

    String s = (a>b && a>c)? "a is greatest":(b>c)?"b is greatest":"c is greatest";
    System.out.println(s);


    }


    }

    ReplyDelete
  92. import java.util.Scanner;
    public class VowelFinder
    {
    public static void main(String args[])
    {
    Scanner ab=new Scanner(System.in);
    char ch;
    System.out.print("Enter an Alphabet : ");
    ch= ab.next().charAt(0);

    if
    (ch=='a' || ch=='A' || ch=='e' || ch=='E' ||
    ch=='i' || ch=='I' || ch=='o' || ch=='O' ||
    ch=='u' || ch=='U'){
    System.out.println(ch+" is a Vowel");
    }
    else
    {
    System.out.println(ch+" is consonant");

    }

    }

    }

    ReplyDelete
  93. import java .util.Scanner;

    class Divisible
    {
    public static void main(String args[])
    {
    int p;
    Scanner ab=new Scanner(System.in);

    System.out.println("Enter number=");
    p=ab.nextInt();

    String s=(p%3==0 && p%5==0)?"Divisible by both":"Not divisible by both";
    System.out.println(s);
    }
    }

    ReplyDelete
  94. // yogesh seroke
    //decimal to binary
    wap to convert decimal to binary
    //Abhishek chauhan


    import java.util.Scanner;

    public class BinaryToDecimal
    {
    public static void main(String args[])
    {
    int num;
    Scanner sc=new Scanner(System.in);

    System.out.print("Enter any integer number: ");
    num = sc.nextInt();

    String str=Integer.toBinaryString(num);
    System.out.println("Binary number is : "+ str);
    }
    }

    ReplyDelete
  95. //yogeshseroke
    //add using without + operator
    import java.util.Scanner;

    public class SumOfTwoNumbersWithOutPlusOperator {

    public static void main(String[] args) {


    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter First Number : ");
    int input1 = scanner.nextInt();
    System.out.print("Enter Second Number : ");
    int input2 = scanner.nextInt();


    int output = input1 -(- input2);

    System.out.println("without operator(" + input1 + ", " + input2 + ") = " + output);

    }

    }

    ReplyDelete
  96. //yogesh seroke
    //even and odd
    class CheckEvenNumberTurnery {
    public static void main( String args[] ) {
    int number = 3;
    String msg = (number % 2 == 0) ? " The number is even!" : " The number is odd!";
    System. out. println(msg);
    }
    }

    ReplyDelete
  97. //yogesh seroke
    //3 and 5
    import java .util.Scanner;

    class Divisible
    {
    public static void main(String args[])
    {
    int p;
    Scanner ab=new Scanner(System.in);

    System.out.println("Enter number=");
    p=ab.nextInt();

    String s=(p%3==0 && p%5==0)?"Divisible by both":"Not divisible by both";
    System.out.println(s);
    }
    }

    ReplyDelete
  98. //yogesh seroke
    // greatest number
    public class Greatestno {
    public static void main(String args[])
    {
    int a=89,b=45,c=50;

    String s = (a>b && a>c)? "a is greatest":(b>c)?"b is greatest":"c is greatest";
    System.out.println(s);


    }


    }

    ReplyDelete
  99. Sandeep kelwa

    class BinaryToDecimal
    {
    public static void main(String args[])
    {
    String binaryString="1010";
    int decimal=Integer.parseInt(binaryString,2);
    System.out.println(decimal);
    }
    }

    ReplyDelete
  100. WAP to check that today is Sunday or not ??

    class SundayorNot
    {
    public static void main(String args[])
    {
    String day="Sunday";
    String res= (day=="Tuesday")?"Sunday":"other day";
    System.out.println(res);
    }
    }

    ReplyDelete
  101. VISHAL SINGH RAJPOOTMay 19, 2022 at 11:08 AM

    WAP to check that today is Sunday or not ??

    class SundayorNot
    {
    public static void main(String args[])
    {
    String day="Sunday";
    String res= (day=="Tuesday")?"Sunday":"other day";
    System.out.println(res);
    }
    }

    ReplyDelete
  102. class BinarytoDecimal

    {
    public static void main (String args [])

    {
    int a=1001;

    double digit = 1*Math.pow(2,0)+0*Math.pow(2,1)+0*Math.pow(2,2)+1*Math.pow(2,3);


    System.out.println((int)digit);


    }

    }

    ReplyDelete

Post a Comment

POST Answer of Questions and ASK to Doubt

Popular posts from this blog

Uncontrolled form input in React-JS

  Uncontrolled form input in React-JS? If we want to take input from users without any separate event handling then we can uncontrolled the data binding technique. The uncontrolled input is similar to the traditional HTML form inputs. The DOM itself handles the form data. Here, the HTML elements maintain their own state that will be updated when the input value changes. To write an uncontrolled component, you need to use a ref to get form values from the DOM. In other words, there is no need to write an event handler for every state update. You can use a ref to access the input field value of the form from the DOM. Example of Uncontrolled Form Input:- import React from "react" ; export class Info extends React . Component {     constructor ( props )     {         super ( props );         this . fun = this . fun . bind ( this ); //event method binding         this . input = React . createRef ();...

JSP Page design using Internal CSS

  JSP is used to design the user interface of an application, CSS is used to provide set of properties. Jsp provide proper page template to create user interface of dynamic web application. We can write CSS using three different ways 1)  inline CSS:-   we will write CSS tag under HTML elements <div style="width:200px; height:100px; background-color:green;"></div> 2)  Internal CSS:-  we will write CSS under <style> block. <style type="text/css"> #abc { width:200px;  height:100px;  background-color:green; } </style> <div id="abc"></div> 3) External CSS:-  we will write CSS to create a separate file and link it into HTML Web pages. create a separate file and named it style.css #abc { width:200px;  height:100px;  background-color:green; } go into Jsp page and link style.css <link href="style.css"  type="text/css" rel="stylesheet"   /> <div id="abc"> </div> Exam...

JDBC using JSP and Servlet

JDBC means Java Database Connectivity ,It is intermediates from Application to database. JDBC has different type of divers and provides to communicate from database server. JDBC contain four different type of approach to communicate with Database Type 1:- JDBC-ODBC Driver Type2:- JDBC Vendor specific Type3 :- JDBC Network Specific Type4:- JDBC Client-Server based Driver  or JAVA thin driver:- Mostly we prefer Type 4 type of Driver to communicate with database server. Step for JDBC:- 1  Create Database using MYSQL ,ORACLE ,MS-SQL or any other database 2   Create Table using database server 3   Create Form according to database table 4  Submit Form and get form data into servlet 5  write JDBC Code:-     5.1)   import package    import java.sql.*     5.2)  Add JDBC Driver according to database ide tools     5.3)  call driver in program         ...