Tuesday, July 5, 2011

Letter Check


package com.evs.objava33.class3;

import static java.lang.Character.isLowerCase;
import static java.lang.Character.isUpperCase;
import sun.java2d.pipe.LoopPipe;

import com.sun.org.apache.bcel.internal.generic.GOTO;

public class LetterCheck {

/**
*
* @param args
*/
public static void main(String[] args) {
char symbol = 'A';
if (isUpperCase(symbol)) {
System.out.println("This is capital letter");
} else if (isLowerCase(symbol)) {
System.out.println("This is small letter");
}

// if ( boolean expression ) {
// statement(s) ;
// }
// else if ( boolean expression ) {
// }

int i = 0, j = 0;
if (i > 1) {
j = i + 1;
} else {
j = 1;
}
j = (i > 1) ? i + 1 : 1;
j = (i > 1) ? ((i > 2) ? i + 2 : 2) : 1;

// i =1, j=1
// i =2, j=4,
// i=3, j=8
System.out.println(i == 1 ? j + 1 : i == 2 ? i + 4 : 8);

if (i == 0) {
System.out.println("Zero");
} else if (i == 1) {
System.out.println("One");
} else if (i == 2) {
System.out.println("Two");
} else {
System.out.println("unknown");
}

System.out.println(i == 0 ? "Zero" : i == 1 ? "One" : i == 2 ? "Two"
: "Unknown");

switch (i) {
case 0:
System.out.println("Zero");
break;
case 1:
System.out.println("One");
break;
case 2:
System.out.println("Two");
break;
default:
break;
}

// // 1. while
// int a = 0; // initialization
// while (a < 10) { // expression / condition
// System.out.println(a); // Statement
// a = a + 1; // increment / iteration operation
// }
//
// // 2. do while
// int b = 0; // init
// do {
// System.out.println(b);// statement
// b++;// increment
// } while (b < 10); // condition / expression
//
// // 3. for
// // for ( initialization ; condition ; increment )
// for (int c = 0, d = 0; c < 10 && d < 10; c++, d++) {
// System.out.println(c);
// }
//

// // 4. For each

loop1: for (int a = 0; a < 3; a++) {
loop2: for (int b = 0; b < 5; b++) {
loop3: for (int c = b; c < 2; c++) {
if (a == c) {
continue loop1;
}
if (a == b) {
break loop1;
}
System.out.println(a + ":" + b + ":" + c);
}
}
}
}
}

No comments:

Post a Comment