0% found this document useful (0 votes)
24 views17 pages

PIJ file2323232

The document outlines a series of Java programming practicals completed by a student named Aditya Jha during their 4th semester at the Integrated Institute of Technology, Dwarka. Each practical includes a specific aim, the Java program code, and its corresponding output. The practicals cover fundamental programming concepts such as data types, control statements, loops, and object-oriented programming.

Uploaded by

27adityajha27
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)
24 views17 pages

PIJ file2323232

The document outlines a series of Java programming practicals completed by a student named Aditya Jha during their 4th semester at the Integrated Institute of Technology, Dwarka. Each practical includes a specific aim, the Java program code, and its corresponding output. The practicals cover fundamental programming concepts such as data types, control statements, loops, and object-oriented programming.

Uploaded by

27adityajha27
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/ 17

integrated institute of technology

DWARKA

NAME ADITYA JHA


SUBJECT PROGRAMING IN JAVA
BTE ROLL NO. 1912111008
CLASS ROLL NO. 307
SEMESTER 4TH SEMESTER
BRANCH ITESM
All Java Practicals
Practical Name Date of practical

1 hello world 03-February-2021

2 creating object 02/10/2021

3 Data type size 17-February-2021

4 Typecasting 17-February-2021

5 Operators 24-February-2021

6 Scanner 24-February-2021

7 If Else statement 03-March-2021

8 nested if else 03-March-2021

9 for loop 10-March-2021

10 nested for loops 10-March-2021

11 while loop 25-March-2021

12 do while loop 25-March-2021

13 switch case 01-April-2021

14 continue statement 01-April-2021

15 break statement 01-April-2021

16 prime number 08-April-2021

Practical -1

AIM : TO CREATE A BASIC HELLO WORLD


PROGRAM.
PROGRAM:
class hello
{
public static void main(String[] args) {
System.out.println("hello");
}
}

OUTPUT:
Practical -2

AIM: write a program to create class


and object.
PROGRAM:

public class boxes

public static void main(String args[])

Box b1= new Box();

b1.setDimension(12,5,2);

b1.showDimension();

class Box

int length, breadth, height;

public void setDimension( int l, int b, int h)

length=l;

breadth=b;
height=h;

public void showDimension()

System.out.println("Length="+length);

System.out.println("Breadth="+breadth);

System.out.println("Height="+height);

Output:

Practical -3
AIM: TO FIND DATATYPESIZE AND RANGE THROUGH
JAVA PROGRAM.

class myclass{

public static void main(String args[]){

System.out.println("Size of byte is:- "+""+(Byte.SIZE/8)+"byte");

System.out.println("Range of
Byte="+Byte.MIN_VALUE+"to"+Byte.MAX_VALUE);

System.out.println("Size of long is:- "+""+(Long.SIZE/8)+"byte");

System.out.println("Range of
Long="+Long.MIN_VALUE+"to"+Long.MAX_VALUE);

System.out.println("Size of short is:- "+""+(Short.SIZE/8)+"byte");


System.out.println("Range of
short="+Short.MIN_VALUE+"to"+Short.MAX_VALUE);

System.out.println("Size of float is:- "+""+(Float.SIZE/8)+"byte");

System.out.println("Range of
Float="+Float.MIN_VALUE+"to"+Float.MAX_VALUE);

System.out.println("Size of double is:-


"+""+(Double.SIZE/8)+"byte");

System.out.println("Range of
Double="+Double.MIN_VALUE+"to"+Double.MAX_VALUE);

System.out.println("Size of integer is:-


"+""+(Integer.SIZE/8)+"byte");

System.out.println("Range of
integer="+Integer.MIN_VALUE+"to"+Integer.MAX_VALUE);

System.out.println("Size of character is:-


"+""+(Character.SIZE/8)+"byte");

System.out.println("Range of
character="+Character.MIN_VALUE+"to"+Character.MAX_VALUE);

OUTPUT:

Practical -4
AIM: TYPE CASTING.

PROGRAM:
public class Typecasting{

public static void main(String args[]){

int a=34;

double b=a;

System.out.println(b);

OUTPUT:

Practical -5
AIM: TO PERFORM OPERATORS ON JAVA.

PROGRAM:

class operator{

public static void main(String args[]){

int a=50;

int b=40;

int c=30;

System.out.println("a+b = "+(a+b));

System.out.println("a-b = "+(a-b));

System.out.println("a*b = "+(a*b));

System.out.println("b/a = "+(b/a));

System.out.println("b%a = "+(b%a));

System.out.println("c%a = "+(c%a));

System.out.println("a==b = "+(a==b));

System.out.println("a!=b = "+(a!=b));

}
OUTPUT:

Practical -6
AIM : TO USE THE SCANNER CLASS IN JAVA.

PROGRAM :

import java.util.Scanner;

class scr{

public static void main(String args[]){

int no;

Scanner obj=new Scanner(System.in);

System.out.println("enter a number");

no=obj.nextInt();

System.out.println("square is :"+(no*no));

OUTPUT :

Practical -7
AIM : TO USE THE IF ELSE STATEMENT.

PROGRAM:
import java.util.Scanner;

class ifelse{

public static void main(String args[]){

Scanner obj=new Scanner(System.in);

System.out.println("enter your salary");

int sal=obj.nextInt();

if (sal>=10000){

int b=(sal*10)/100;

sal=sal+b;

else{

int b=(sal*5)/100;

sal=sal+b;

System.out.println("Total salary is"+sal);

OUTPUT:

Practical -8
AIM : TO CREATE NESTED IF ELSE PROGRAM IN JAVA.

PROGRAM:

import java.util.Scanner;

class nie{

public static void main(String args[]){

Scanner obj=new Scanner(System.in);


int a,b,c;

System.out.println("enter first number");

a=obj.nextInt();

System.out.println("enter second number");

b=obj.nextInt();

System.out.println("enter third number");

c=obj.nextInt();

if(a>b){

if(a>c){

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

else{

System.out.println("Greater value is"+c);

else{

if(b>c){

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

Else

System.out.println("Greater value is"+c);

OUTPUT:
Practical -9
AIM: TO LEARN ABOUT FOR LOOPS IN JAVA.

PROGRAM:

class forloop{

public static void main(String[] args) {

int a=2;

for (int i=1;i<=10 ;i++ ) {

System.out.println(a+i);

OUTPUT:

Practical -10
AIM: TO LEARN NESTED FOR LOOPS IN JAVA.

PROGRAM:

class nestedforloops{

public static void main(String[] args) {

for (int i=1;i<=5 ;i++ ) {

for (int j=1;j<=i ;j++ ) {


System.out.print("*");

System.out.println("");

OUTPUT:

Practical -11
AIM : TO USE WHILE LOOP IN JAVA.

PROGRAM :

import java.util.Scanner;

class While{

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

System.out.println("enter a number : ");

int n=sc.nextInt();

while(n<=50){

System.out.println("value of the number : "+n);

n++;

System.out.println("\n");

Output:-
Practical -12
AIM : To use DO while loop in java.

PROGRAM :

class Test{

public static void main(String[] args) {

int no=2;

do{

System.out.println(no);

no=no+2;

while(no<=100);

Output:
Practical -13
Aim :- To use switch case in java.
PROGRAM :

import java.util.Scanner;

class abc{

public static void main(String[] args) {

Scanner obj=new Scanner(System.in);

int roll;

System.out.println("enter roll number");

roll=obj.nextInt();

switch(roll){

case 101:

System.out.println("student name : Faizan");

break;

case 102:

System.out.println("student name: soham");

break;

case 103:

System.out.println("student name : kaushal");

break;
default:

System.out.println("not found");

Output :-

Practical - 14
Aim :- to use continue statement in java.
PROGRAM :

class test{

public static void main(String[] args) {

int i;

for (i=0;i<=10 ;i++ ) {

if(i==5)

continue;

System.out.println(i);

Output :-
Practical - 15
Aim :- to use break in java.

PROGRAM :

class test{

public static void main(String[] args) {

int i;

for (i=0;i<=10 ;i++ ) {

if(i==5)

break;

System.out.println(i);

Output :-

Practical - 16
Aim : Prime Numbers
PROGRAM :

import java.util.Scanner;

class Primenumber{

public static void main(String args[]) {

int a, b;

Scanner sc = new Scanner(System.in);

System.out.println("Enter the number");


a = sc.nextInt();

b=2;

while(b<=a-1)

if (a % b == 0) {

System.out.println("number is not a prime number " + a);

break;

b = b+1;

if (b==a) {

System.out.println("Number is prime " + a);

Output :-

You might also like