B.Sc.(IT) 4th Semester
Practical Question Paper Set
(Give any one set to each student randomly)
Set- 1
Write a program to print “ Welcome to Java Programming” on the screen
public class welcome
{
public static void main (String args[])
{
System.out.println("Welcome to Java programming");
}
}
Using a case statement, write a shell program to read a command (eg., who, cal, ls, ps) from the user and execute it.
echo "let me know what you want to do" while : a=0; do echo "1 : who command 2: cal command 3: ls command 4 : ps command 5: exit " echo "enter your choice : " read a case $a in
1) echo `who`;;
2) echo `cal`;;
3) echo `ls`;;
4) echo `ps`;;
5) exit ;;
*) echo "this option is not available" ;; esac done
Set- 2
Using awk, sum the file sizes in your working directory and print the results.
ls -l | awk '/^-/ {total+=$5} END{print "Total of all file sizes "total}'
Write a program to check whether the given two numbers are equal. If not then find the greater of the given two numbers.
import java.io.*; import java.math.*; class Greatest
{
public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n1,n2; System.out.println("Enter the values for n1,n2"); n1=Integer.parseInt(br.readLine()); n2=Integer.parseInt(br.readLine());
if( n1 == n2) { System.out.println("Both the numbers are equal"); } else if( n1 > n2 ) { System.out.println("First number is greater than second"); } else { System.out.println("Second number is greater than first"); } }
}
Set- 3
Using switch and case statements write a program to add, subtract, multiply and divide the two numbers
import java.io.*; public class Cal
{
public static void main(String args[])throws Exception
{
int a,b,c=0;
BufferedReader