0% found this document useful (0 votes)
39 views

Document For Programming

The document contains code snippets and flowcharts providing computer answers for 5 programming questions. It includes Java code to print even numbers, calculate grade averages, convert numbers to words, and calculate exponents using various loops. Flowcharts illustrate the logic for printing even numbers, grade calculation, number conversion, and exponent calculation.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Document For Programming

The document contains code snippets and flowcharts providing computer answers for 5 programming questions. It includes Java code to print even numbers, calculate grade averages, convert numbers to words, and calculate exponents using various loops. Flowcharts illustrate the logic for printing even numbers, grade calculation, number conversion, and exponent calculation.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Kaira A.

Perez TVL-Programming
Grade 11 – Phython August 14, 2022

Computer Answers for Remedial:


Answers for 1, 2, 3, 4, and 5.
1. public class EvenNumber {

/**
* @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;

Scanner grades = new Scanner(System.in);


System.out.print("Enter Grades\n");
System.out.print("Science: ");
grade1 = grades.nextInt();
System.out.print("English: ");
grade2 = grades.nextInt();
System.out.print("Math: ");
grade3 = grades.nextInt();
sum=grade1+grade2+grade3;
res=sum/3;
System.out.print("Result is\n"+res);
grades.close();

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(a). public static void main(String[] args) {


int a=1;
Scanner num = new Scanner(System.in);
System.out.print("Input a number\n");
a = num.nextInt();
switch(a){
case 1:
System.out.print("One\n");
break;
case 2:
System.out.print("Two\n");
break;
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
case 3:
System.out.print("Three\n");
break;
case 4:
System.out.print("Four\n");
break;
case 5:
System.out.print("Five\n");
break;
case 6:
System.out.print("Six\n");
break;
case 7:
System.out.print("Seven\n");
break;
case 8:
System.out.print("Eight\n");
break;
case 9:
System.out.print("Nine\n");
break;
case 10:
System.out.print("Ten\n");
break;
default:
System.out.print("Invalid Number");
break;
Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
}
}

}
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

4(a). While loop:

public static void main(String[] args) {


String name="Kaira";
int count=0;
while(count<=100){
System.out.print(name);
count++;
}
}

4(b). do while loop:

public static void main(String[] args) {


Kaira A. Perez TVL-Programming
Grade 11 – Phython August 14, 2022
String name="Kaira";
int count=0;
do{
System.out.println(name);
count++;
}
while(count<=100);
}

4(c) for loop:

public static void main(String[] args) {


String name="Kaira";
for(int count=0; count<=100; count++){
System.out.println(name);
}
}

Results:

5. Three answers

5(a) while loop:

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

5(b) do while loop:

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);
}

5(c) for loop

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

Flowcharts for answers 1, 2, 3, 4, and 5


1.

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:

String name = while


START Print “name”
“Kaira” (count
count +++
int count = 0; <=100)
TRUE
C) For Loop:

START

string name = “Kaira


int count = 0;

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

int base, exp,


result = 1;

while
(exp > 0)

result = result *
base;
exp--;

Print Answer

END

END Print Answer

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

int base, exp,


result = 1;

(exp > 0)

result = result *
base;
exp--;
exp--;

Print Answer

END

You might also like