Back Up Next

Vejanje

Stavek if

if ( boolean-expression ) {
    statements;
}
[ else {
    statements;
}  ]
Primer:
class test {
        public static void main(String argv[]) {
            int starost=10; 

            if (starost < 18) {
              System.out.println("Majhen si...");
              System.out.println("Moras se malo zrasti");
            } 
            else
              System.out.println("Ti si pa velik");
        }
}

Stavek switch

  switch ( int-value ) {
    case int-value1:
      break;
    case int-value2:
      break;
    default:
  }
Primer:
class test {
        public static void main(String argv[]) {
            int num=10; 
            switch (num) {
              case 1:
                System.out.println("one"); break;
              case 2:
                System.out.println("two"); break;
              default:
                System.out.println("many");
            }
        }
}
BackUpNext