Solution

Published on June 2016 | Categories: Documents | Downloads: 16 | Comments: 0 | Views: 278
of 10
Download PDF   Embed   Report

Comments

Content

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 java.io.*; public class BasicCalc { public static void main(String a[])throws IOException { DataInputStream in = new DataInputStream(System.in); 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; switch (i) { case 1: System.out.println("Result after Adding" + " " + (m + n) ); break; case 2: System.out.println("Result after Substracting" + " " + ( m - n)); break; case 3: System.out.println("Result after Multiplying" + " " + (m * n)); break; case 4: System.out.println("Result after Dividing" + " " + (m / n)); break; default: System.out.println("This is not a valid input parameter" ); break; } } }

// Solution 5 class EvenOddSum { static int sum1, sum2; static int n[] ={ 2, 3, 4, 5, 6, 7, 92, 65, 45, 87 }; public static void main(String a[])

{ for (int i = 0; i <> { if (n[i] % 2 == 0) { System.out.println(n[i] + " " + "*" + " " + "Even"); sum1 = sum1 + n[i]; } else { System.out.println(n[i] + " " + "*" + " " + "Odd"); sum2 = sum2 + n[i]; } } System.out.println("sum of even no. is " + sum1); System.out.println("sum of odd no. is " + sum2); } } //Solution 6 import java.io.*;

class PrimeNumber { public static void main(String[] args) throws Exception { int i; BufferedReader bf = new BufferedReader( new InputStreamReader(System.in)); System.out.println("Enter number:");

int num = Integer.parseInt(bf.readLine()); System.out.println("Enter 2nd number:"); int num2 = Integer.parseInt(bf.readLine()); System.out.println("Prime number: "); for (i = num; i <> { int j; for (j = 2; j <> { int n = i % j; if (n == 0) { break; } } if (i == j) { System.out.print(" " + i); } } } }

//Solution 9 class classBox { static int width, depth, height; dimention() { width = 10;

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

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

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

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

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

11. Write a program to demonstrate the overriding of constructor methods for the program no. 9. 12. Write a program to concatenate two strings 13. Write a program to find whether a given string is a palindrome or not 14. Write a program to change the case of the given string 15. Write a program to create a thread by extending the thread class Enjoy coding these programs.!! :) For more help visit www.chatat.socialgo.com and join me. Regards, Ravish. 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... ? May (2) About Me My Photo Ravish Kumar How can i say... btw... i hate lier's n backstabber's. View my complete profile

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close