0% found this document useful (0 votes)
9 views6 pages

Oops Assesstments

w? getting? hard? extremely? hard.? So? i?have? studies? what's? going? on? there? for? a? few? days? and?have? made? some? observat
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)
9 views6 pages

Oops Assesstments

w? getting? hard? extremely? hard.? So? i?have? studies? what's? going? on? there? for? a? few? days? and?have? made? some? observat
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/ 6

OOPS PROGRAMS ASSESSMENTS

Program no:1
 JAVA program to print an integer (Entered by the user(

 Programing code
import java.util.Scanner;
class program1{
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
System.out.println("Enter an integer");
int a =sc.nextInt();
System.out.println("You have enterd: "+a); } }
 Output
Enter an integer
2
You have enterd:2

=== Code Execution Successful ===


 Compilation
https://www.programiz.com/online-compiler/9XKOkxlHYQWny
click on above link to get Realtime code compilation
OOPS PROGRAMS ASSESSMENTS

Program no:2
 Java Program to Add Two Integers

 Programing code
class program2 {
public static void main(String[] args) {
int a=2, b=3;
System.out.println("The sum of "+a+" and "+b+" is:"+(a+b));
}
}
 Output
The sum of 2 and 3 is:5

=== Code Execution Successful ===


 Compilation
https://www.programiz.com/online-compiler/18tYrKG20DKwu

click on above link to get Realtime code compilation


OOPS PROGRAMS ASSESSMENTS

Program no:3
 Java Program to Multiply two Floating Point Numbers

 Programing code
class program3 {
public static void main(String[] args) {
float a=2.25f, b=3.65f;
System.out.println("The Multiplication of "+a+" and "+b+" is:"+
(a*b));
}
}
 Output
The Multiplication of 2.25 and 3.65 is:8.212501

=== Code Execution Successful ===


 Compilation
https://www.programiz.com/online-compiler/0kNGYqBmtAaxg

click on above link to get Realtime code compilation


OOPS PROGRAMS ASSESSMENTS

Program no:4
 Java Program to Find ASCII Value of a character
 Programing code
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a character: ");
char ch = scanner.next().charAt(0);
int asci = (int) ch;
System.out.println("The ASCII value of " + ch + " is: " + asci);
}
}
 Output
Enter a character: b
The ASCII value of b is: 98

=== Code Execution Successful ===


 Compilation
https://www.programiz.com/online-compiler/1BTwHw0vDFCMs
click on above link to get Realtime code compilation
OOPS PROGRAMS ASSESSMENTS

Program no:5
 Java Program to Compute Quotient and Remainder
 Programing code
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the dividend: ");
int dividend = scanner.nextInt();
System.out.print("Enter the divisor: ");
int divisor = scanner.nextInt();
int quotient = (dividend / divisor);
int remainder = (dividend % divisor);
System.out.println("Quotient: " + quotient);
System.out.println("Remainder: " + remainder); } }
 Output
Enter the dividend: 37
Enter the divisor: 3
Quotient: 12
Remainder: 1
=== Code Execution Successful ===
 Compilation
https://www.programiz.com/online-compiler/85xbZrDTWVZX9
click on above link to get Realtime code compilation
OOPS PROGRAMS ASSESSMENTS

Program no:6
 Java Program to Swap Two Numbers
 Programing code
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the First no: ");
int n1 = sc.nextInt();
System.out.print("Enter the second no: ");
int n2 = sc.nextInt();
System.out.println("Before swaping: "+"\n First no:" +n1+"\n
Second no:"+n2);
System.out.println("After swaping: "+"\n First no:"+ n2+"\n
Second no:"+n1);} }
 Output
Enter the First no: 6
Enter the second no: 4
Before swaping:
First no:6
Second no:4
After swaping:
First no:4
Second no:6
=== Code Execution Successful ===
 Compilation
https://www.programiz.com/online-compiler/8vCRI2G0saClc
click on above link to get Realtime code compilation

You might also like