You are on page 1of 4

DAY-4

question-1

package assignments;

public class Product {


int product_id ;
String product_name ;
static int quantity =30;
double price;
static String l="sum :";

Product(){

}
Product(int a,String k,double c){
product_id = a;
product_name = k;
price = c;

void show(){
System.out.println(product_id+" "+product_name+" "+price+" "+quantity);
}

public static void main(String[] args) {

int x=20;
int y=50;
int b=x+y;

// TODO Auto-generated method stub


Product p1=new Product(1,"kitkat",98.64);
Product p2=new Product();

// call by using class name

System.out.println(Product.quantity);

//call through default constructor


System.out.println(p2.quantity);

// call by using parameterized constructor


p1.show();

System.out.println(l+b);

}
QUESTION-2

package assignments;
import java.util.Scanner;

public class fruits {

public fruits() {
// TODO Auto-generated constructor stub
}

public static void main(String[] args) {


//char a;

System.out.println("enter the alphabet");


Scanner a=new Scanner(System.in);

char ch=a.next().charAt(0);
switch(ch)
{
case'A':System.out.println("APPLE");
break;
case'B':System.out.println("BANANA");
break;
case'O':System.out.println("ORANGE");
break;
case'P':System.out.println("PINE APPLE");
break;
case'M':System.out.println("MANGO");
break;
case'W':System.out.println("WATER MELON");
break;

default:
System.out.println("No fruit exist ");
}

}
}

QUESTION-3
package assignments;
import java.util.Scanner;

public class check {

public check() {
// TODO Auto-generated constructor stub
}

public static void main(String[] args) {


// TODO Auto-generated method stub
int a;
int b;
System.out.println("Enter value of a");
Scanner scan=new Scanner(System.in);
a=scan.nextInt();
System.out.println("Enter value of b");
Scanner e=new Scanner(System.in);
b=e.nextInt();

if(a==b) {
System.out.println("Both are same");
}else if(a>b) {
System.out.println("a is greater than b");
}else {
System.out.println("b is greater than a");
}

QUESTION-4

package assignments;
import java.util.Scanner;

public class bit_wise {

public static void main(String[] args) {


// TODO Auto-generated method stub
int x;
int y;
int c=0;
System.out.println("Enter the value of x :");
Scanner scan=new Scanner(System.in);
x=scan.nextInt();
System.out.println("Enter the value of x :");
Scanner bscan=new Scanner(System.in);
y=bscan.nextInt();

c=x & y;
System.out.println("x & y ="+c);
c=x|y;
System.out.println("x | y ="+c);
c=x^y;
System.out.println("x ^ y ="+c);
c= ~x;
System.out.println("~x ="+c);
c= x<<y;
System.out.println("x << y ="+c);
c=x >>y;
System.out.println("x >> y ="+c);
}

QUESTION - 5

package assignments;
import java.util.Scanner;

public class strings {

public static void main(String[] args) {

System.out.println("Enter string 1");


Scanner m=new Scanner(System.in);
String a=m.nextLine();
System.out.println("Enter string 2");
Scanner k=new Scanner(System.in);
String b=k.nextLine();

System.out.println(a.equals(b));
}

You might also like