Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
26 views

Void Int: Integers Main Arguments C

This document contains 3 Java code examples: 1) A for loop that prints integers from 1 to 10. 2) An if/else statement that prints different messages depending on a boolean value. 3) A for-each loop that prints command line arguments. It also asks as a practice question to write a program to find the factorial of a number.

Uploaded by

Pranay Kinra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Void Int: Integers Main Arguments C

This document contains 3 Java code examples: 1) A for loop that prints integers from 1 to 10. 2) An if/else statement that prints different messages depending on a boolean value. 3) A for-each loop that prints command line arguments. It also asks as a practice question to write a program to find the factorial of a number.

Uploaded by

Pranay Kinra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Example 1: Print integers

class Integers {
public static void main(String[] arguments) {
int c;
//declaring a variable
/* Using for loop to
repeat instruction
execution */
for (c = 1; c <= 10; c++) {
System.out.println(c);
}
}

Output:

If else control instructions:

class Condition {
public static void main(String[] args) {
boolean learning = true;
if (learning) {
System.out.println("Java programmer");
}
else {
System.out.println("What are you doing here?");

}
Output:

Command line arguments:

class Arguments {
public static void main(String[] args) {
for (String t: args) {
System.out.println(t);
}
}
}

Practice question
Write a program to find factorial of n no.

You might also like