Monday, March 23, 2020

BlueJ Program On Competition and Banner


Details of The Program: CLICK HERE

import java.io.*; 
public class S 
{ 
public void show() throws Exception 
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
String str[]; 
int n, i, j;

System.out.println("Enter the number of names: "); 
n = Integer.parseInt(br.readLine());

str = new String[n]; 
for(i=0;i< n;i++)
{

System.out.print("\nEnter Name No "+(i+1) + ":"); 
str[i] = br.readLine();

} 
int max = 0; 
for(i=0;i< n;i++)
{

if(str[i].length() >max) 
max = str[i].length(); 
/* Length of the longest name will be stored in variable 'max' */ 
} 
System.out.println("OUTPUT:" ); 
for(i=0;i< max;i++)
{ 
for(j=0;j< n;j++)

{
/* characters from each name will be displayed with a tab at right to maintain the gap, if there is no character in any name at the location specified by 'charAt(i)' means 'i' has a value less than the length of the string, only tabular space will be printed */ 
if(i< str[j].length())

System.out.print(str[j].charAt(i)+"\t"); 
else 
System.out.print("\t"); 
}

System.out.println(); 
} 
}
public static void main(String args[]) throws Exception 
{ 
S obj=new S(); 
obj.show(); 
} 
}


Variable Description

Type
Name
Use

BufferedReader
br
Intakes limit from user


String
str
Names are stored

Int
i
Loop control variable

int
j
Loop control variable

int
n
Stores the number of students



Algorithm

Step 1: Create BufferedReader object ‘br’ and an int type variable ‘n’ to store the number of strings to be stored in the string type array.

Step 2: create the string array ‘str’ according to the value stored in ‘n’.

Step 3: Store the strings in ‘str’.

Step 4: store the length of the maximum length string in an int variable ‘max’




Step 5: To display, run the outer loop ‘max’ times and the inner loop will run ‘n’ number of times and from the inner loop display the characters of each string in separate columns. Whenever any stri


Back To 2018 Computer Practical Paper: CLICK HERE

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner