Midterm Data Structure
Midterm Data Structure
Create an algorithm for the following problems/tasks and execute it using Java Programming
Language. Use the space provided for your algorithms and codes.
REPETITION
Sample Output:
SELECTION
4. Write a program the let you enter a mark between 0 and 100 and that will test its value and
print appropriately. “PASS” or “FAIL”.
5. Write a program that let you enter 5 marks between 0 and 100 and that prints out in each
case the letter grade.
Sample output:
6. Write a program that let you print 20 random real numbers between 0 to 100.
OUTPUT
ANSWER NO. 1:
ALGORITHM
I=1
If i<=10
Print i
I++
________________________________________
CODES
package com.Algorithm;
public class Numbersonetoten {
public static void main(String[] args) {
System.out.println("Printing 1 to 10 numbers!");
int i = 10;
{
System.out.println( i + ",");
}
}
}
__________________________________
ANSWER NO. 2:
ALGORITHM
Int i=10
If i>=1
Print i
i—
________________________________________
CODES
package com.cc103.com.cc104bsit2a;
}
_________________________________________
ANSWER NO. 3:
ALGORITHM
Ask User to enter number
That will result rows in making triangle of “ * ”
________________________________________
CODES
package com.Algorithm;
import java.util.Scanner;
int k = 0;
}
}_________________________________________
ANSWER NO. 4
ALGORITHM
________________________________________
CODES
import java.util.Scanner;
System.out.println("Passed");
else{
System.out.println("FAILED");
}
}
}
_________________________________________
ANSWER NO. 5:
ALGORITHM
If grade is between 1 – 49
Print F
If grade is between 50 – 59
Print D
If grade is between 60 – 69
Print C
If grade is between 70 – 79
Print B
If grade is between 80 – 89
Print A
Print A+
________________________________________
CODES
package com.Algorithm;
import java.util.Scanner;
System.out.println("Enter 5 Grades");
for(int i=0;i<Score.length;i++)
{
System.out.print("Grade "+(i+1)+" :");
Score[i]= console.nextInt();
System.out.println("Remarkings");
for(int i=0;i<Score.length;i++)
{
System.out.println("D grade");
}
else if (Score[i] >= 60 && Score[i] <=69)
{
System.out.println("C grade");
}
else if (Score[i] >= 70 && Score[i] <=79)
{
System.out.println("B grade");
}
else if (Score[i] >= 80 && Score[i] <=89)
{
System.out.println("A grade");
}
else if (Score[i] >= 90 && Score[i] <=100)
{
System.out.println("A+ grade");
}
}
_________________________________________
ANSWER NO. 6:
ALGORITHM
CODES
package com.Algorithm;
import java.util.Random;
int random;
System.out.println("Random Numbers:");