Learn java app (4) 반응형 썸네일형 리스트형 Program to Illustrate Enhanced For Loop Program: class EnhancedForLoop { public static void main(String[] args) { int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29}; System.out.println("Enhanced for loop:"); for (int t: primes) { System.out.println(t); } } } Output: Enhanced for loop: 2 3 5 7 11 13 17 19 23 29 Program to Print Multiplication Table Program: import java.util.Scanner; class MultiplicationTable{ public static void main(String args[]){ int n, c; System.out.println("Enter an integer to print it's multiplication table: "); Scanner in = new Scanner(System.in); n = in.nextInt(); System.out.println("Multiplication table of " + n); for (c = 1; c Program to know the functionality of Static Block Program: class StaticBlock { public static void main(String[] args) { System.out.println("Main method is executed."); } static { System.out.println("Static block is executed before main method."); } } Output: Static block is executed before main method. Main method is executed. find odd or even Program: import java.util.Scanner; class OddOrEven { public static void main(String args[]) { int x; System.out.println("Enter an integer to check if it is odd or even"); Scanner in = new Scanner(System.in); x = in.nextInt(); if (x % 2 == 0) System.out.println("The number is even."); else System.out.println("The number is odd."); } } Output: Enter an integer to check if it is odd or even 5 The n.. 이전 1 다음