Skip to content
Snippets Groups Projects
Commit 389845af authored by Vilho Kivihalme's avatar Vilho Kivihalme
Browse files

english version

parents
Branches
No related tags found
No related merge requests found
public class Addition{
//All java programs start with main method
public static void main(String[] args){
if(args.length !=2){
System.out.println("Give two whole number arguments!");
System.exit(0); //This quits the program
}
//Changes the arguments to integers
//Note: the program crashes if the arguments are not whole numbers
int num1 = Integer.parseInt(args[0]);
int num2 = Integer.parseInt(args[1]);
int sum = num1+num2;
//print the sum
System.out.println("Numbers "+ num1 + " and " + num2+" sum is: " +sum);
//program ends
}
}
\ No newline at end of file
public class factorial{
/*
* Prints the factorial of given argument
*/
public static void main(String[] args){
int num = Integer.parseInt(args[0]);
int factorial =1
for(int i = 1; i<=num;i++){
factorial = factorial*i;
}
System.out.println(factorial);
}
class HelloWorld{
public static void main(String[] args){
System.out.println("Hello World!")
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment