Severity: Warning
Message: fopen(/tmp/ci_sessiondo7sng0toef4h5f3u4f30hqfme82a1hh): failed to open stream: No space left on device
Filename: drivers/Session_files_driver.php
Line Number: 176
Backtrace:
File: /var/www/html/application/controllers/Project.php
Line: 10
Function: __construct
File: /var/www/html/index.php
Line: 311
Function: require_once
Severity: Warning
Message: session_start(): Failed to read session data: user (path: /tmp)
Filename: Session/Session.php
Line Number: 143
Backtrace:
File: /var/www/html/application/controllers/Project.php
Line: 10
Function: __construct
File: /var/www/html/index.php
Line: 311
Function: require_once
Printing hollow pattern using JAVA programming language while taking a number of rows and columns as an input.
The purpose is to print a hollow pattern while taking a number of rows and columns as input from the user in the JAVA programming language.
We are taking rows and column numbers as input from users.
"i" and "j" are iterators of the loop.
How the loops are working: When the value of i=1 or i equals the number of rows or when the value of j=1 or j equals the number of columns,
then "*" will be printed, otherwise " "(Blank space) will be given. After each iteration of a row, the next line will be printed.
import java.util.*;
public class hollowPattern {
public static void main(String[] args) {
int col, row,i,j;
Scanner sc = new Scanner(System.in);
System.out.println("Enter Rows: ");
row = sc.nextInt();
System.out.println("Enter Columns: ");
col = sc.nextInt();
for(i=1;i<=row;i++) {
for(j=1;j<=col;j++) {
if(i==1 || i==row || j==1 || j==col) {
System.out.print("* ");
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
Submitted by Kartik Rakesh Khandelwal (kkwal27)
Download packets of source code on Coders Packet
Comments