FinishedFirst
This commit is contained in:
@ -100,6 +100,56 @@ public class Basics {
|
|||||||
System.out.println("Something else!");
|
System.out.println("Something else!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Given the age of a person as an input, output their age group.
|
||||||
|
Here are the age groups you need to handle:
|
||||||
|
Child: 0 to 11
|
||||||
|
Teen: 12 to 17
|
||||||
|
Adult: 18 to 64
|
||||||
|
Sample Input
|
||||||
|
42
|
||||||
|
Sample Output
|
||||||
|
Adult
|
||||||
|
*/
|
||||||
|
int ages = sc.nextInt();
|
||||||
|
if (ages > 0 && ages <= 11) {
|
||||||
|
System.out.println("Child");
|
||||||
|
}else if(ages <= 17){
|
||||||
|
System.out.println("Teen");
|
||||||
|
} else if (ages <= 64) {
|
||||||
|
System.out.println("Adult");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Your math teacher asked you to calculate the sum of the numbers 1 to N, where N is a given number.
|
||||||
|
Task: Take an integer N from input and output the sum of the numbers 1 to N, inclusive.
|
||||||
|
Sample Input:
|
||||||
|
10
|
||||||
|
Sample Output:
|
||||||
|
55
|
||||||
|
*/
|
||||||
|
|
||||||
|
int number = sc.nextInt();
|
||||||
|
int sum = 0;
|
||||||
|
while (number > 0) {
|
||||||
|
sum += number;
|
||||||
|
number--;
|
||||||
|
}
|
||||||
|
System.out.println(sum);
|
||||||
|
|
||||||
|
/*
|
||||||
|
The factorial of a number N is equal to 1 * 2 * 3 * ... * N
|
||||||
|
For example, the factorial of 5 is 1* 2 * 3 * 4 * 5 = 120.
|
||||||
|
Create a program that takes a number from input and output the factorial of that number.
|
||||||
|
*/
|
||||||
|
long fact = 1;
|
||||||
|
int num = sc.nextInt();
|
||||||
|
for (int i = 2; i <= num; i++) {
|
||||||
|
fact *= i;
|
||||||
|
}
|
||||||
|
System.out.println(fact);
|
||||||
|
|
||||||
sc.close();
|
sc.close();
|
||||||
sci.close();
|
sci.close();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user