Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Java Fundamentals - Lab 1 Practice Problems

CSE 201 - Advanced Programming August 24, 2012 NOTES: Write all programs within NetBeans environment, and feel free to utilize any features of the IDE that may help. Please follow the following package structure: in.ac.iiitd.cse201.<firstname><rollno>.<#lab> Avoid going into your friends code packages and messing up their code. If such activities are found, we will not hesitate to take strict action (including reduction of grades) against perpetrators. This is clearly not an exhaustive set of practice problems. Feel free to be creative and explore other alternative problem settings to program. Some of the problems below may require some additional exploration of the language/IDE features than those taught in the class. While every care is taken to make them closely related to the topics covered in the class, there may be some which have slipped this filter. Do not treat this as an issue, but use this to learn more about Java (take TAs help if needed). Practice Problems: 1. Write a simple helloworld program within NetBeans, and print the greeting as many times as the number of characters in the greeting string. 2. Describe what happens if you omit each of the following from the program: (a) public for the class declaration (b) public for the main function (c) args argument for the main function 3. Generating the divisor matrix: Divisor matrix of a given size N is an N N matrix, where an entry (i, j) is a if either i divides j or j divides i. Otherwise, entry (i, j) is a blank space. Write a Java program to print the divisor matrix for a chosen value of N > 15. Use the StringBuilder class in this program. 4. Fibonacci numbers are the numbers in the sequence defined through: Fn = Fn1 + Fn2 with seed values F0 = 0, and F1 = 1. A program that printed the first few elements of the sequence was discussed in the class. We add a new twist: print the first k (some chosen value > 10) Fibonacci numbers which are not divisible by any Fibonacci number (n > 2) before. 5. Generate a sequence of random UTF-16 characters, and form a String using these characters. Choose an appropriate length (not millions, but something like 10-50 characters). (HINT: Remember that UTF-16 characters are variable length, but at most have the same size as an int type. So, is it possible to use a random int to represent a random char?)

You might also like