lab programs on java and dbms for students access

RohitKumar363 10 views 4 slides Oct 03, 2024
Slide 1
Slide 1 of 4
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4

About This Presentation

lab programs for easy understanding and implementing


Slide Content

HELLO WORLD class HelloWorld { // Your program begins with a call to main(). // Prints "Hello, World" to the terminal window. public static void main(String args []) { System.out.println ("Hello, World"); } } ADDING OF TWO INTEGERS import.java.io.*; class Main { public static void main(String[] args ) { int first = 10; int second = 20; // add two numbers int sum = first + second; System.out.println (first + " + " + second + " = " + sum); } }

operators: class Main { public static void main(String[] args ) { // declare variables int a = 12, b = 5; // addition operator System.out.println ("a + b = " + (a + b)); // subtraction operator System.out.println ("a - b = " + (a - b)); // multiplication operator System.out.println ("a * b = " + (a * b)); } } ASCII VALUE OF THE CHARACTER public class AsciiValue { public static void main(String[] args ) { char ch = 'a'; int ascii = ch ; // You can also cast char to int int castAscii = (int) ch ; System.out.println ("The ASCII value of " + ch + " is: " + ascii); System.out.println ("The ASCII value of " + ch + " is: “+ castAscii ); } }

SWAPPING OF TWO NUMBERS public class SwapNumbers { public static void main(String[] args ) { float first = 1.20f, second = 2.45f; System.out.println ("--Before swap--"); System.out.println ("First number = " + first); System.out.println ("Second number = " + second); // Value of first is assigned to temporary float temporary = first; // Value of second is assigned to first first = second; // Value of temporary (which contains the initial value of first) is assigned to second second = temporary; System.out.println ("--After swap--"); System.out.println ("First number = " + first); System.out.println ("Second number = " + second); } }

Class reverse { Public static int reverse( int num ) { Int reverse=0; While( num !=0) { Reverse=reverse*10+num%10; Num/=10; } Return reverse; } }
Tags