0% found this document useful (0 votes)
695 views8 pages

Index: Computer Workshop-Java (CS 306) Practical File

The document contains a practical file for a Java computer workshop. It includes 10 programming assignments completed by the student with their name, experiment title, submission date, remarks and signature. For each assignment, the question asked is provided along with the student's code submission and output. The assignments include programs to compare strings, find reverse of a number, perform arithmetic operations using switch case, sort an array, and print a series using a do-while loop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
695 views8 pages

Index: Computer Workshop-Java (CS 306) Practical File

The document contains a practical file for a Java computer workshop. It includes 10 programming assignments completed by the student with their name, experiment title, submission date, remarks and signature. For each assignment, the question asked is provided along with the student's code submission and output. The assignments include programs to compare strings, find reverse of a number, perform arithmetic operations using switch case, sort an array, and print a series using a do-while loop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

COMPUTER WORKSHOP- JAVA

(CS 306)
PRACTICAL FILE

KRISHNA PRATAP KUSHWAH

INDEX
S.NO NAME OF EXPERIMENT DATE OF SUBMISSION REMARK SIGNATURE

1. PROGRAM TO PRINT A MESSAGE 10/10/2020


2. PROGRAM TO SWAP TWO NUMBERS 10/10/2020
3. PROGRAM TO CHECK NUMBER IS ARMSTRONG 21/10/2020
4. PROGRAM TO FIND VOLUME OF BOX 21/10/2020
5. PROGRAM OF A COMPARE STRING 29/11/2020
6. PROGRAM TO FING REVERSE OF A NUMBER 29/11/2020
7. PROGRAM TO PERFORM ALL ARITHMETIC 29/11/2020
OPERATIONS USING SWITCH CASE STATEMENTS
8. WRITE A PROGRAM FOR SWITCH CASE 29/11/2020
STATEMENTS
9. PROGRAM TO SORT THE SERIES IN ASCENDING 29/11/2020
ORDER USING ARRAY.
10. WRITE A PROGRAM TO PRINT AS SERIES USING 29/11/2020
DO WHILE LOOP

0905CS191101
Q Write a program of a compare string.
Ans:
package MSLjava;

import java.util.Scanner;

public class Compare {


public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String password = "JAVA123";
System.out.println("Enter your password");
String a = in.nextLine();
if((password.compareTo(a)) ==0 )
System.out.println("Password is Correct!");
else
System.out.println("Password is incorrect");
}
}

output:
Q. Write a program to find the reverse of a number.
Ans:
package MSLjava;

import java.util.Scanner;

public class Reverse_no {


public static void main(String[] args) {
int n, reverse = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number");

n = sc.nextInt();

while (n != 0)
{
reverse = reverse * 10;
reverse = reverse + n % 10;
n = n/10;
}
System.out.println("reverse number is: "+reverse);
}
}

Output:

Q. Write a program to perform all arithmetic operations using switch


case statements.
package MSLjava;

import java.util.Scanner;

public class All_Arth_op {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter two numbers: ");
double first = sc.nextDouble();
double second = sc.nextDouble();

System.out.println("Enter an operator (+, -, *, /): ");


char op = sc.next().charAt(0);

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;

public class switchCase {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int day ;
String dayString;

System.out.println("Enter a number from 1 to 7");


day = sc.nextInt();

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;

public class sort {


public static void main(String[] args) {
int [] arr = new int[] {5, 2, 8, 7, 1};
int temp = 0;

System.out.println("Element of Original array: ");


for(int i = 0; i< arr.length; i++){
System.out.print(arr[i] + " ");
}
for (int i = 0; i<arr.length; i++){
for (int j = i+1; j< arr.length; j++){
if (arr[i]> arr[j]){
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
System.out.println("\n" + "Element of sorted array: ");
for(int i = 0; i< arr.length; i++){
System.out.print(arr[i] + " ");
}
}
}

Output:
Q. Write a program to print as series using do while
loop
Ans:
package MSLjava;

public class series {


public static void main(String[] args) {
int i = 0;
do {
System.out.print(i+" ");
i++;
}
while (i<=15);
}
}

Output:

You might also like