Document For Programming
Document For Programming
Perez TVL-Programming
Grade 11 – Phython August 14, 2022
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
for(int a=23; a<=40; a++){
a=a+1;
System.out.print("\nValue of "+ a);
}
Results:
2.
package grades;
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
import java.util.Scanner;
/**
*
* @author Abe Perez
*/
public class Grades {
public static void main(String[] args) {
double grade1, grade2, grade3, sum ,res;
if(res>=60){
System.out.print("*Smiley Face");
}
else{
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
System.out.print("\nTry again");
}
}
Results:
3. (Two answers)
}
3(b). public static void main(String[] args) {
Scanner num = new Scanner(System.in);
System.out.print("Input a number\n");
int value = num.nextInt();
if(value == 1)
{
System.out.println("One");
}
else if(value == 2)
{
System.out.println("Two");
}
else if(value == 3)
{
System.out.println("Three");
}
else if(value == 4)
{
System.out.println("Four");
}
else if(value == 5)
{
System.out.println("Five");
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
}
else if(value == 6)
{
System.out.println("Six");
}
else if(value == 7)
{
System.out.println("Seven");
}
else if(value == 8)
{
System.out.println("Eight");
}
else if(value == 9)
{
System.out.println("Nine");
}
else if(value == 10)
{
System.out.println("Ten");
}
else{
System.out.print("Invalid Number\n");
}
}
}
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
Results:
4. Three answers
Results:
5. Three answers
package power;
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
import java.util.Scanner;
/**
*
* @author Abe Perez
*/
public class Power {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int base, exp, result=1;
Scanner num = new Scanner(System.in);
System.out.print("Input a base:\n");
base = num.nextInt();
System.out.print("Input a exponent:\n");
exp = num.nextInt();
num.close();
while(exp>0){
result=result*base;
exp--;
}
System.out.println("Answer is \n"+result);
}
}
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
package power;
import java.util.Scanner;
/**
*
* @author Abe Perez
*/
public class Power {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int base, exp, result=1;
Scanner num = new Scanner(System.in);
System.out.print("Input a base:\n");
base = num.nextInt();
System.out.print("Input a exponent:\n");
exp = num.nextInt();
num.close();
do{
result=result*base;
exp--;
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
}
while(exp>0);
System.out.println("Answer is \n"+result);
}
package power;
import java.util.Scanner;
/**
*
* @author Abe Perez
*/
public class Power {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int base,expo,result=1;
Scanner num = new Scanner(System.in);
System.out.print("Input a base:\n");
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
base = num.nextInt();
System.out.print("Input a exponent:\n");
expo = num.nextInt();
num.close();
for(int exp=expo; exp>0; exp--){
result=result*base;
}
System.out.println("Answer is \n"+result);
}
Results:
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
START
int a = 23;
FALSE
a<= 42
END TRUE
a = a + 1;
a ++;
system.out.print
(“Value of” +a);
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
2.
START
read grade 1,
grade 2,
grade 3;
sum = grade 1 +
grade 2 +
grade 3;
res = sum/3
False
res >= 60 “TRY AGAIN”
True
END
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
3. Two Answers:
A)
START
VALU
E =1
VALU
E=2
VALU
E=3
“ONE”
VALUE
=4
“TWO” VALUE
=5
VALUE
“THREE” =6
VALUE
=7
“FOUR”
VALUE
=8
“TEN”
“FIVE” VALUE
=9
VALUE
“SIX” “EIGHT” = 10
“SEVEN” “NINE”
END
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
B) START
CASE 1
ONE
CASE 2 TWO
CASE 3 THREE
CASE 4 FOUR
CASE 5 FIVE
CASE 6 SIX
CASE 7 SEVEN
CASE 8 EIGHT
CASE 9 NINE
CASE TEN
10
DEFAULT INVALID
NUMBER
END
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
4)
A) While Loop:
START
FALSE
String name = “Kaira”
int count = 0;
While
(count<
=100)
TRUE
print “name”
count ++
END
END
FALSE
B)
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
Do while:
START
FALSE count
<=100
END
TRUE count ++
System.out.print
(name);
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
5. Three Answers:
A) While
START
while
(exp > 0)
result = result *
base;
exp--;
Print Answer
END
while
(exp > 0)
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
B) Do while loop
- result = result *
START int base, exp,
base;
result = 1;
exp--;
C) For Loop
START
(exp > 0)
result = result *
base;
exp--;
exp--;
Print Answer
END