0% found this document useful (0 votes)
1 views

Java

This is my presentations pdf

Uploaded by

sudinabhargavi28
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Java

This is my presentations pdf

Uploaded by

sudinabhargavi28
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Java

public class Main {

public static void main(String[] args) {

System.out.println("Hello World");

public class Main {

public static void main(String[] args) {

// Create integer variables

int length = 4;

int width = 6;

int area;

// Calculate the area of a rectangle

area = length * width;

// Print variables

System.out.println("Length is: " + length);

System.out.println("Width is: " + width);

System.out.println("Area of the rectangle is: " + area);

Every line of code that runs in Java must be inside a class

System is a built-in Java class that contains useful members, such as out,
which is short for "output". The println() method, short for "print line", is
used to print a value to a file

Here system belongs to static class. And output is object. And print line is a
static method.
import java.util.*;

class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.println("Enter a value:");

System.out.println("Enter b value:");

int a = scanner.nextInt();

int b = scanner.nextInt();

System.out.println("a value is: " + a);

System.out.println("b value is: " + b);

int c=a+b;

System.out.println("Sum is: " + c);

You might also like