0% found this document useful (0 votes)
36 views11 pages

Java Practicals Printready

The document discusses Java programs that use logical operators, check if a number is even or odd, use switch case statements, print star patterns, use do-while loops, and perform type casting between basic data types.

Uploaded by

relicplaya086
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)
36 views11 pages

Java Practicals Printready

The document discusses Java programs that use logical operators, check if a number is even or odd, use switch case statements, print star patterns, use do-while loops, and perform type casting between basic data types.

Uploaded by

relicplaya086
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/ 11

1.1)Write a programme by using logical operators.

class ifdemo {

public static void main(String args[])

int x = 5;

int y = 10;

if (x == 5 && y == 10) {

System.out.println("x is 5 and y is 10.");

if (x < y || x == 5) {

System.out.println("x is less than y or x is 5.");

if (!(x > y)) {

System.out.println("x is not greater than y.");

}
2)Write any program to check even or odd.

import java.util.*;

class evenoddpj

public static void main(String args[])

int n;

Scanner sc=new scanner(System.in);

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

n=sc.nextInt();

if(n%2==0)

System.out.println("Your entered number is even:");

else

System.out.println("Your entered number is odd:");

}
Q1.) Write a programme to check switchcase.

import java.util.Scanner;

class switchit

public static void main(String[] args)

Scanner pj = new Scanner(System.in);

System.out.print("Enter a character: ");

char ch = pj.next().charAt(0);

switch(ch)

case 'a':

case 'e':

case 'i':

case 'o':

case 'u':

case 'A':

case 'E':

case 'I':

case 'O':

case 'U':

System.out.println(ch + " is a vowel.");


break;

default:

System.out.println(ch + " is a consonant.");

break;

}
5.2. Write any program to print pyramids of Star/patterns using increment/decrement.

class donger

public static void main(String[] args)

int i,j,num=7;

for ( i = 1; i <= num; i++) {

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

System.out.print("* ");

System.out.println();

}
6.2) Write a program to display number 1to50 using do-while loop.

class dowhilepj{

public static void main(String[] args)

int i = 1;

do {

System.out.println(i);

i++;

} while (i <= 50);

}
9.2. Write a program to convert variable basic data type and show the result of explicit
typecasting

class explicit

public static void main(String[] args)

int num = 10;

double num1 = (double)num;

System.out.println("num: " + num + ", num1: " + num1);

}
7-8.3. Write a program to implicitly typecast lower range data type to larger storage size
datatype.

class implicitpj

public static void main(String[] args)

byte b = 6;

short s = b;

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

System.out.println("short = " + s);

You might also like