Posts

Showing posts from September, 2021

Assignment Operators

Image
 Assignment Operators PROGRAM: class   AssignmentOperators {      public   static   void   main ( String   args [])     {          int   a ;          a = 5 ;          int   b = a ;          System . out . println ( b );          b += a ;          System . out . println ( b );          b *= a ;          System . out . println ( b );     } } // 5 // 10 // 50

Arithmetic Operators

Image
 Arithmetic Operators  I/P: 10 5 O/P: 15 5 50 2 0 PROGRAM: import   java . util .*; public   class   ArithmeticOperators  {      public   static   void   main ( String   args [])     {          Scanner   sc = new   Scanner ( System . in );          int   a = sc . nextInt ();          int   b = sc . nextInt ();          int   sum = a + b ;          int   sub = a - b ;          int   mul = a * b ;          int   quo = a / b ;          int   rem = a % b ;          System . out . println ( sum );  ...

How to get input from the user in Java Programming

Image
 How to get input from the user in Java Programming I/P: Enter a sentence hi hello everyone Enter a number 5 Enter a number which accepts upto 6 decimal digits 12.333333 Enter a number which accepts upto 15 decimal digits 11.22222222222222 Enter a byte 100 Enter a boolean true Enter a word hi Enter a single character h O/P: hi hello everyone 5 12.333333 11.22222222222222 100 true hi h PROGRAM: package   B asics ; import   java . util .*; public   class   InputFromUser  {      public   static   void   main ( String   args [])     {          Scanner   sc = new   Scanner ( System . in );          System . out . println ( "Enter a sentence" );          String   h = sc . nextLine ();          System . out . println ( "Ent...

Variables & Datatypes in Java Programming

Image
 Variables & Datatypes in Java Programming                        PROGRAM: public   class   DataTypes {      public   static   void   main ( String   args [])     {          //Primitive Datatypes          byte   a =  100 ; //size:1 byte ,range:-128 to 127          short   b =  5000 ; //size:2 bytes,range:-32768 to 32767          int   c = 5 ; //size:4 bytes;          long   d = 15000000000000l ; //size:8 bytes;          float   e =  5.923456f ; //size:4 bytes; sufficient to store 6 to 7 ...

Program to print Hello World

Image
 Program to print Hello World    PROGRAM: public   class   HelloWorld  {           public   static   void   main ( String   args [])     {          System . out . println ( "Hello World" );          System . out . println ( "Hi" );     } } // Hello World // Hi

Program to find the position of the given element present in the Array

Image
 Program to find the position of the given element present in the Array I/P: 5 7 8 11 12 3 11 O/P: 3 I/P: 5 7 8 11 12 3 5 O/P: element is not found PROGRAM: import   java . util .*; public   class   Kposition  {         public   static   void   main ( String []  args ) {         Scanner   sc = new   Scanner ( System . in );         int   iNum = sc . nextInt ();         int   iArr []= new   int [ iNum ];         int   iCount = 0 ;         for ( int   i = 0 ; i < iNum ; i ++)        {            iArr [ i ]= sc . nextInt ();        }         int...

Check the given number is Palindrome or not without using String

Image
 Check the given number is Palindrome or not without using String I/P: 121 O/P: Palindrome I/P: 12345 O/P: Not a palindrome PROGRAM: import   java . util .*; public   class   palindrome  {      public   static   void   main ( String []  args ) {          Scanner   sc = new   Scanner ( System . in );          int   iNum = sc . nextInt ();          int   n = iNum ;          int   iSum = 0 ;          while ( n > 0 )         {              int   rem = n % 10 ;              iSum = iSum * 10 + rem ;       ...

PROGRAM TO FIND EXTRA ELEMENT PRESENT IN THE ARRAY BY COMPARING ANOTHER ARRAY

Image
  PROGRAM TO FIND EXTRA ELEMENT PRESENT IN THE ARRAY BY COMPARING ANOTHER ARRAY I/P: 7 6 2 4 6 8 9 10 12 2 4 6 8 10 12 O/P: The extra element is 9 Its index is 4 PROGRAM: import   java . util .*; public   class   Extraelement  {      public   static   void   main ( String   args [])     {          Scanner   sc = new   Scanner ( System . in );          int   iNum = sc . nextInt ();          int   iNum2 = sc . nextInt ();          int   arr []= new   int [ iNum ];          int   arr2 []= new   int [ iNum2 ];          for ( int   i = 0 ; i < iNum ; i ++)         {    ...

Check the given two strings are Anagram to each other or not

Image
 Check the given two strings are Anagram to each other or not      I/P: listen silent O/P: it is Anagram I/P: cat dog O/P: Not an Anagram PROGRAM: import   java . util .*; public   class   Anagram  {      public   static   void   main ( String []  args ) {                   Scanner   sc = new   Scanner ( System . in );          String   s1 = sc . next ();                   String   s2 = sc . next ();          char   cA []= s1 . toCharArray ();          Arrays . sort ( cA );                   char   cB []= s2 . toCharArra...

PROGRAM TO ADDING A * BEFORE A WORD WHOSE LENGTH IS FOUR

Image
 PROGRAM TO ADDING A  "*"  BEFORE A WORD WHOSE LENGTH IS FOUR I/P: 9 this is lots of fun for every java programmer O/P: [****, this, is, ****, lots, of, fun, for, every, ****, java, programmer] PROGRAM: import   java . util .*; public   class   AddingStarBeforelengthisFour  {      public   static   void   AddingStar ( ArrayList < String >  al , int   iNum )     {          String   temp = "" ;                  Scanner   sc = new   Scanner ( System . in );           for ( int   i = 0 ; i < iNum ; i ++)          {              temp = sc . next ();          ...

Program to find the substring which starts with vowel and ends with consonant

Image
 Program to find the substring which starts with vowel and ends with consonant I/P: hello O/P: el I/P: he is a good boy O/P: e is PROGRAM: import   java . util .*; public   class   StartsVowelendsConstant  {      public   static   void   main ( String []  args ) {               Scanner   sc = new   Scanner ( System . in );           String   s1 = sc . nextLine ();           int   iV = 0 , iC = 0 ;           for ( int   i = 0 ; i < s1 . length (); i ++)          {               if ( s1 . charAt ( i )== 'a'  ||  s1 . charAt ( i )== 'e'  ||  s1 . charAt ( i )== 'i'  ...

PRODUCT OF DIGITS

Image
 PRODUCT OF DIGITS I/P: 12356 O/P: 180 I/P: 542 O/P: 40 PROGRAM: import   java . util .*; public   class   ProductOfDigits  {      public   static   void   main ( String []  args ) {                   Scanner   sc = new   Scanner ( System . in );          int   iNum = sc . nextInt ();          int   product = 1 ;          while ( iNum > 0 )         {              int   rem = iNum % 10 ;              product *= rem ;              iNum /= 10 ;       ...

Program to Convert the given Decimal number to Roman Letters

Image
 Program to Convert the given Decimal number to Roman Letters   I/P: 24 O/P: XX1V I/P: 36 O/P: XXXVI PROGRAM: import   java . util .*; public   class   DecimalToRoman  {      public   static   void   main ( String []  args ) {                   Scanner   sc = new   Scanner ( System . in );          int   iNum = sc . nextInt ();          String   s3 = "" ;          while ( iNum > 0 )         {              if ( iNum >= 10 )             {                  s3...

Program to Replace Vowels to Uppercase in a String

 Program to Replace Vowels to Uppercase in a String I/P: hi hello O/P: hI hEllO PROGRAM: import   java . util .*; public   class   Vowelcapital  {      public   static   void   main ( String []  args ) {          Scanner   sc = new   Scanner ( System . in );          String   s1 = sc . nextLine ();          for ( int   i = 0 ; i < s1 . length (); i ++)         {              switch ( s1 . charAt ( i ))             {              case   'a' :                  s1 = s1 . replace ( ...

Program to check the given number is Perfect number or not

 Program to check the given number is Perfect number or not I/P: 6 O/P: Perfect Explanation : 6 divisors are 2 , 3 ,1  its sum is equal to the given num so its a perfect num PROGRAM: import   java . util .*; public   class   perfect  {      public   static   void   main ( String []  args ) {               Scanner   sc = new   Scanner ( System . in );          int   iNum = sc . nextInt ();          int   sum = 0 ;          int   a = iNum ;          for ( int   i = 1 ; i < iNum ; i ++)         {              if ( iNum % i == 0 )       ...

BRILLIANT BINGO

 BRILLIANT BINGO I/P: 7892 O/P: 5 EXPLANATION : Check this video to understand better: https://youtu.be/sJX6FD8MZOo Given a number in each round of the game the players have to multiply their number with the round number.  The game stops when a player gets all the numbers from 0 to 9 and its a brilliant game bingo. 7892*1 => 7 8 9 2=7892*2=1 5 7 8 4=7892*3= 2 3 6 7 6=7892*4= 3 1 5 6 8=7892*5= 3 9 4 6 0 0 1 2 3 4 5 6 7 8 9 O/P: 5 PROGRAM: import   java . util .*; public   class   BrilliantBingo  {           public   static   void   Bingo ( int   iNum )     {          TreeSet < Integer >  ts = new   TreeSet <>();          int   i = 1 , r = 0 ;          while ( ts . size ()!= 10 ){         ...

Program to perform Union operations

 Program to perform Union operations I/P: 5 3 1 2 3 4 5 7 8 3 O/p: [1, 2, 3, 4, 5, 7, 8] 7 PROGRAM: import   java . util .*; public   class   Union  {      public   static   void   main ( String   args [])     {          Scanner   sc = new   Scanner ( System . in );          int   n1 = sc . nextInt ();          int   n2 = sc . nextInt ();          TreeSet < Integer >  ts = new   TreeSet <>();          for ( int   i = 0 ; i < n1 ; i ++)         {              ts . add ( sc . nextInt ());         }     ...