You are on page 1of 10

1. public class welcome { public static void main (String args[]) { System.out.

println("Welcome to Java programming"); } } Solutions to JAVA and UNIX Programming. Hie! friends this is Ravish, join my blog and get the solutions to your Problems especially in JAVA. Monday, September 21, 2009 Solutions to Helpful JAVA Programming Questions Lab Assignment Java Lab Assignment Solutions

// Solution 1 class welcome { public static void main(String a[]) { System.out.println("Welcome to Java Progamming"); } } // Solution 3 import*; public class BasicCalc { public static void main(String a[])throws IOException { DataInputStream in = new DataInputStream(; System.out.println("What do you want to do? \n 1. Add, \n 2. Substra ct, \n 3. Multiply, \n 4. Divide"); int i = Integer.parseInt(in.readLine()); //int i=4; int m, n; m = 10;

n = 5.out. 92. break. switch (i) { case 1: System.println("Result after Adding" + " " + (m + n) ).out.println("This is not a valid input parameter" ). 7.n)). break. case 2: System. public static void main(String a[]) .println("Result after Multiplying" + " " + (m * n)). static int n[] ={ 2. case 4: System. 3.out.println("Result after Substracting" + " " + ( m . 65. default: System. 5.out.println("Result after Dividing" + " " + (m / n)). break. 6.out. } } } // Solution 5 class EvenOddSum { static int sum1. 4. 87 }. break. break. sum2. 45. case 3: System.

sum2 = sum2 + n[i].out. } } //Solution 6 import java.out.println("sum of even no. BufferedReader bf = new BufferedReader( new InputStreamReader(System.out.{ for (int i = 0. .io.println("sum of odd[i] + " " + "*" + " " + "Even"). i <> { if (n[i] % 2 == 0) { System. System.println("Enter number:"). System.out.*.println(n[i] + " " + "*" + " " + "Odd"). class PrimeNumber { public static void main(String[] args) throws Exception { int i. } else { System. sum1 = sum1 + n[i]. is " + sum1). is " + sum2). } } System.out.

out.out. System. } } } } //Solution 9 class classBox { static int width. for (j = 2.print(" " + i). dimention() { width = 10. height. j <> { int n = i % j. .parseInt(bf.println("Enter 2nd number:").out. int num2 = Integer. i <> { int j.parseInt(bf. if (n == 0) { break. System.readLine()). } } if (i == j) { num = Integer.println("Prime number: ").readLine()). depth. for (i = num.

box.out.println("volume of box is :" + " " + box).volume(). } void add(int x. 30). height = 20.depth = 5. q.out. } public static void main(String args[]) { demo q = new demo().out.add(10). } } //Solution 10 class demo { void add(int a) { System. .println(a). } public static void main(String args[]) { dimention box = new dimention(). q.add(20. } void volume() { int box = width * depth * height.println(x + y). int y) { System. System.

} } //Solution 12 class con { public static void main(String a[]) { String a1 = "Ravish". over.println(s). String a2 = "Kumar".out. } public static void main(String args[]) { B over = new B().} } //Solution 11 class A { String s = "Ravish". void display() { System.display(). } } class B extends A { void display() { System.println(s + " " + "Kumar"). .out.

println("\n").socialgo.equals("exit")). for (int i = 0.out. in)). class case { public static void main(String ar[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System. System.out. .readLine().length().out.println("Enter any String").print(ch).!! :) For more help visit and join me. Or you can mail me at } } Enjoy coding these programs.System. System.charAt(i)).println("and to quit write Exit ").toUpperCase(str. i <> { char ch = Character.concat(" " + a2)).out. String str. do { str = br. System.chatat.*. int textLength = str. } } while (!str.out. } } // Solution 14 import java.

your login account and the current date in the dd-mm-yyyy format to the file. . Ravish. For a file named myfile in the working directory. c) give write privileges to everyone except the owner d) allow the owner and group members to execute myfolder. apple use the ls command to list only those files that a) consist of four letters b) begin with the letter c c) end with the letter e d) have the second letter o 3. All privil eges are to be removed from everyone else. lotus. cola. 4. c) remove write privileges from everyone except the owner d) allow the owner and group members to execute myfile and give only the owner permission to read or write to it. Append the outputs of the commands to sho w the users logged into your system. All privileges are to be removed for everyone else. Put a long-running process in the background and check the accuracy of the sl eep command. do the following: a) allow everyone to list files in myfolder. if any. orange. No other privileges are to be chang ed. Only the owner gets read or write permission. remove or add files. lemon. Write an interactive shell using I/O redirection to accept input from file1. Posted by Ravish kumar at 11:46 AM 0 comments Labels: java lab assignment Monday. Assuming you have a directory containing the following files: sprite. choco. b) allow the owner to and group members to list. 7. Use the echo command to display the line UNIX is fun to learn Redirect the displayed line to a file. 1. The ls command with the R option lists the files in the specified directory an d also subdirectories. For a directory myfolder in your working directory. No other privilege is to be changed b) allow the owner and group members to read and write the file. 2009 UNIX and Shell Programming Subject: UNIX And Shell Programming.Regards. 6. put stdout in file2 and stderr in file3. book. do the following: a) give everyone permission to read myfile. 5. 2. Use this with a suitable pip-and-filter arrangeme nt to determine whether a file exists in the account logged in. May 4.

Write a shell program in which an infinite loop prompts a user for file name s to be removed and remove the files. arg2 and arg3.8. and al so write a main program to create a circle object and to find the area by callin g the function area () in circle class and display the result on the screen. Write a class Box with the variable width. Write a program to print Welcome to Java Programming on the screen 2. For more help visit http://www.chatat. Write a program to print all the prime numbers between n and m. Use trap to exit when finished. 5. 12. 10. who. 7. Write a shell program to test for arguments arg1. 3. Using switch and case statements write a program to add. ls. Using a case statement. sum the file sizes in your working directory and print the result s. Write a program to add the two matrices. depth and height and constructor t o assigning the values for these variables and a method to find the volume of th e box and also write the main program. 14. U se the /etc/passwd file as input.Write a background command to edit all the files in the directory replacing t he word while with until. 15. Write a shell program to extract and sort all the users in the file system. Using for loop write a program to print the table of a given number on the sc reen. Regards. Write a class circle which consists of functions getdata() and area(). and find th e volume of the box. 11. 13. If not then find the greater of the given two numbers.. subtract . Write a program to find the even sum and the odd sum in the given array 6. prompt the user for them. Write a shell program that adds the integers 1 to 100 and displays the resul t with a suitable and join me. c al. UNIX and Shell Programming Helpfull Ques on Java Programming.socialgo. write a shell program to read a command (eg. If they are not present. Using awk. Ravish. Write a shell program to translate the /etc/passwd file into uppercase and tr anslate the : delimiter into tab characters. ps) from the user and execute it. 8. Posted by Ravish kumar at 1:20 AM 3 comments Labels: chatat. Enjoy coding these programs. Write a shell program using if-the-else to test whether a variable name is a directory or a file. . 9. Write a program to demonstrate the method overloading for sum ( ) function. Print the result on the screen 10. 16. multiply and divide the two numbers 4. Subject: JAVA Programming 1. which creates the box object. 9. Write a program to check whether the given two numbers are equal.

Posted by Ravish kumar at 1:04 AM 0 comments Labels: helpfull java programs Home Subscribe to: Posts (Atom) Followers Blog Archive ? 2009 (3) ? September (1) Solutions to Helpful JAVA Programming Questions La.. Ravish.chatat. ? May (2) About Me My Photo Ravish Kumar How can i say. Write a program to demonstrate the overriding of constructor methods for the program no. 9. 12. Regards..11. Write a program to concatenate two strings and join me. Write a program to find whether a given string is a palindrome or not 14. View my complete profile .. Write a program to change the case of the given string 15. btw.... Write a program to create a thread by extending the thread class Enjoy coding these programs.!! :) For more help visit www. i hate lier's n backstabber's.socialgo.