LAB 1: Software Quality Assurance Lab Sheet: Software Requirements PART 1 Please
ID: 3585689 • Letter: L
Question
LAB 1: Software Quality Assurance Lab Sheet: Software Requirements PART 1 Please refer to below software requirements, read carefully. Students are requested to write a Java program basedon To calculates area of square. A program declares the following variables: 1. An integer variable namedx 2. An integer vaniable namedy (to store area vahue) In the program be sure to input a value from user to variablex (length value) above. The program should then output 1. the final area (y)of the square Source Code (Write the source code):Explanation / Answer
PART - 1:
Source Program:
import java.util.Scanner;
public class SquareArea {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int x,y;
System.out.println("Enter the Length of the Square:");
x = s.nextInt();
y = x*x;
System.out.println("Final Area of the Square is:"+y);
}
}
Output:
Enter the Length of the Square:
8
Final Area of the Square is:64
PART- II
Source Program:
import java.util.Scanner;
public class MatrixOperation {
public static void main(String[] args) {
int rows, columns; //Declaring variables rows and Columns
Scanner s = new Scanner(System.in);
//Reading rows using Scanner object
System.out.println("Enter number of rows:");
rows = s.nextInt();
//Reading columns using Scanner object
System.out.println("Enter number of columns:");
columns = s.nextInt();
//Declaring array dynamically
int array[][] = new int[rows][columns];
//Creating array
for(int i=0; i<rows; i++){
for(int j=0; j<columns; j++){
array[i][j] = i; // Storing value at each index
}
}
//Printing array
for(int i=0; i<rows; i++){
for(int j=0; j<columns; j++){
System.out.print(array[i][j]+" ");
}
System.out.println();
}
}
}
Output:
Enter number of rows:
10
Enter number of columns:
5
0 0 0 0 0
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
6 6 6 6 6
7 7 7 7 7
8 8 8 8 8
9 9 9 9 9
Software Requirements:
1) An integer variable named rows
2) An integer variable named columns
3) Creating a array named array of size rows X columns
4) Storing values into each index position of array with row value for every column iteration.
5) Iterate the array and finally print the array with all indices.