Presentation is loading. Please wait.

Presentation is loading. Please wait.

Instructor: Mainak Chaudhuri

Similar presentations


Presentation on theme: "Instructor: Mainak Chaudhuri"— Presentation transcript:

1 Instructor: Mainak Chaudhuri mainakc@cse.iitk.ac.in
More Examples Instructor: Mainak Chaudhuri

2 Checking case class upperCaseCharacter{
public static void main(String arg[]){ char c=‘0’; boolean isuppercase, islowercase; isuppercase = ((c >= ‘A’) && (c <= ‘Z’)); islowercase = ((c >= ‘a’) && (c <= ‘z’)); System.out.ptintln(“The character is ” + c + “. Uppercase: ” + isuppercase); }

3 Digits in AP class digitsInAP{ public static void main(String arg[]){
int x = 121; int d0, d1, d2; boolean isAP; d0 = x % 10; d1 = (x/10) % 10; d2 = x/100; isAP = ((d0+d2) == (2*d1)); System.out.println(“The number is: ” + x + “. Digits in AP? ” + isAP); }

4 Divisibility by 4 class divisibleByFour{
public static void main(String arg[]){ int x = 121; int lastTwoDigits; boolean isdivBy4; lastTwoDigits = x%100; isdivBy4 = ((lastTwoDigits % 4) == 0); System.out.println(“The number is: ” + x + “. Divisible by 4? ” + isdivBy4); }

5 Exchanging numbers class swapBad{
public static void main(String arg[]){ int x = 121; int y = 200; System.out.println(“x: ” + x + “, y: ” + y); x = x + y; // Could overflow y = x – y; x = x – y; }

6 Exchanging numbers class swapGood{
public static void main(String arg[]){ int x = 121; int y = 200; int temp; System.out.println(“x: ” + x + “, y: ” + y); temp = x; x = y; y = temp; }


Download ppt "Instructor: Mainak Chaudhuri"

Similar presentations


Ads by Google