Scenario: There are 1 to 100 numbers. Each number should be
keep in the each column like from A column to Z column ie 1
to 26. From 27 to 52 should be in 2nd row in the excel
sheet. This has to be continue till 100. How do you write
Java program and what are various methods.

Answer Posted / vishal

public class NumberPlacing {

int k=0;
int n=4;
int val=0;
int[]a=new int[101];

public void printInTabularForm(){
int noOfRows = 100/26;
int rowStart = 1;
int setEnd = 26;

for(int i=rowStart; i<=setEnd; i++){
System.out.print(i+"\t");
if(i == 100){
break;
}else if(i==setEnd){
rowStart = i;
setEnd = i+26;
System.out.println();
}
}
}

public static void main(String args[]){
NumberPlacing num=new NumberPlacing();
num.printInTabularForm();
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does those terms actually mean included in the j.d.k i.6?

1605


What are the six ways to use this keyword?

610


What is an array in java?

640


Can you explain the private protected field modifier?

571


What is time complexity algorithm?

548






What super () does in java?

486


What is an 8 bit word?

596


Can constructor return value?

512


The following program reads data (details of students) from a file named students.txt and converts it into e-mail addresses. The results are written to a file named studentemail.txt. students.txt consists of a number of lines, each containing the data of a student in colon delimited format: Last Name:First Name:Student Number Each input record is converted to an e-mail address and written to studentemail.txt in the following format: the first character of the last name + the first character of the first name + the last four digits of the student number + “@myunisa.ac.za” import java.io.*; public class EmailConverter { public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader(new FileReader ("students.txt")); PrintWriter output = new PrintWriter(new FileWriter ("studentemail.txt")); String line = input.readLine(); while (line != null) { // Extract the information for each student String[] items = line.split(":"); // Generate the email address String email = "" + items[0].charAt(0) + items[1].charAt(0) + items[2].substring(4,8) + "@myunisa.ac.za"; email = email.toLowerCase(); // Output output.println(email); line = input.readLine(); } input.close(); output.close(); } } Rewrite the class so that it handles possible errors that may occur. In particular, it should do the following: • It should catch at least three appropriate exceptions that might occur, and display suitable messages. • At this stage, the program will not run correctly if there is an empty line in the input file. Change the program so that if an empty line is encountered, an exception is thrown and the empty line is ignored. This exception should be handled with the display of a suitable error message. • Before the e-mail address is added to the output file, check if the student number has 8 digits. If not, throw an InvalidFormatException (which the program should not handle itself)

1457


How to display all the prime numbers between 1 and 100

507


What are the fileinputstream and fileoutputstream?

571


What is the exact difference in between unicast and multicast object? Where we will use?

558


Give differences between Quicksort & Mergesort. When should these sorts be used and what is their running time?

572


Can a class be protected in java?

506


What is java english?

496