Index: Computer Workshop-Java (CS 306) Practical File
Index: Computer Workshop-Java (CS 306) Practical File
Index: Computer Workshop-Java (CS 306) Practical File
(CS 306)
PRACTICAL FILE
INDEX
S.NO NAME OF EXPERIMENT DATE OF SUBMISSION REMARK SIGNATURE
0905CS191101
Q Write a program of a compare string.
Ans:
package MSLjava;
import java.util.Scanner;
output:
Q. Write a program to find the reverse of a number.
Ans:
package MSLjava;
import java.util.Scanner;
n = sc.nextInt();
while (n != 0)
{
reverse = reverse * 10;
reverse = reverse + n % 10;
n = n/10;
}
System.out.println("reverse number is: "+reverse);
}
}
Output:
import java.util.Scanner;
double result;
switch (op){
case '+':
result = first + second;
break;
case '-':
result = first - second;
break;
case '*':
result = first * second;
break;
case '/':
result = first / second;
break;
default:
System.out.println("Operator is not correct! ");
return;
}
System.out.println(first + " " + op + " " + second + " = " +
result);
}
}
Output:
Q. Write a
program for switch
case statements
Ans:
package MSLjava;
import java.util.Scanner;
switch (day){
case 1:
dayString = "Monday";
break;
case 2:
dayString = "Tuesday";
break;
case 3:
dayString = "Wednesday";
break;
case 4:
dayString = "Thursday";
break;
case 5:
dayString = "Friday";
break;
case 6:
dayString = "Saturday";
break;
case 7:
dayString = "Sunday";
break;
default:
dayString = "Invalid selection";
}
System.out.println("The selected day is: " + dayString);
}
}
Output:
Q. Write a program to sort the series in ascending order
using array.
package MSLjava;
Output:
Q. Write a program to print as series using do while
loop
Ans:
package MSLjava;
Output: