TRICK PROGRAMS

 TRICK PROGRAMS: IN THIS BLOG I 
AM SHARING SOME TRICKY PROGRAMS WRITTEN IN JAVA LANGUAGE.

1.Add two numbers without using '+' operator:

          import java.util.Scanner;

           class Main{

           public static void main(String args[]){

                        int x;

                         int y;

                         int add;

                         Scanner sc=new Scanner(System.in);

                          System.out.println("Enter two numbers:");

                         x=sc.nextInt();

                         y=sc.nextInt();

                         add=x-(-y);

                          System.out.println("Addition is" +add);

            }

          }

2.Substract two numbers  without using '-' operator:

           import java.util.Scanner;

               class Main{

               public static void main(String args[]){

               int x;

                  int y;

                    int sub;

                    Scanner sc=new Scanner(System.in);

                     System.out.println("Enter two numbers:");

                     x=sc.nextInt();

                        y=sc.nextInt();

                        sub=x+(~y+1);

                        System.out.println(" Result of ("+x+") - ("+y+")is   " +sub);

                  }

                  }



If you have any doubt ,please let me know

Post a Comment (0)
Previous Post Next Post