0
class lower_caseToUpperCase {
public static void main(String[] args)
throws java.io.IOException {
     char ch, ignore;
     int case_change = 0;
     do {
      System.out.print("Enter any number of characters: ");
      ch = (char) System.in.read();
         do {
         ignore = (char) System.in.read();
              }while(ignore != '\n'); 
         if(ch >= 'a' && ch <= 'z') {
           ch -= 32;//shows error if you use ch = ch - 32;
            System.out.println(ch);
               case_change++;
             }
          else if(ch >='A' && ch <='Z') {
             ch += 32;//same as above
               System.out.println(ch);
                 case_change++;
              }
         } while(ch != '.');
       System.out.print("No. of case changes = " + case_change);
    }
   }

whenever i use char = char +32 it shows loose conversion error but when i use char += 32 it runs fine. why is it so? please help..

Dipesh BC
  • 37
  • 5

1 Answers1

2

It is because 32 is integer, so when you write char = char + int you're getting warning

but operator += is special one, in java it is resolves to char = (char)(char + int) so you don't see warning because of implicit case

Iłya Bursov
  • 23,342
  • 4
  • 33
  • 57
  • Thanks for the quick reply that's the reason i was thinking when i later used (char)(char +32) why the program was running fine. :) – Dipesh BC Mar 11 '18 at 01:41