JAVA   30
java2-
Guest on 16th March 2023 07:21:37 AM


  1. import java.util.Scanner;
  2.     import java.*;
  3.     class Product
  4.     {
  5.     int pCode,price;
  6.     String pName;
  7.     Product(int pCode,String pName,int price)
  8.     {
  9.     this.pCode=pCode;
  10.     this.pName=pName;
  11.     this.price=price;
  12.     }
  13.     }
  14.     public class Products
  15.     {
  16.     public static void main(String[]args)
  17.     {
  18.     Scanner sc=new Scanner(System.in);
  19.     System.out.print("Enter product code :");
  20.     int pCode=sc.nextInt();
  21.     System.out.print("\nEnter product name :");
  22.     String pName=sc.next();
  23.     System.out.print("\nEnter product price :");
  24.     int price=sc.nextInt();
  25.     Product[]ps=new Product[3];
  26.     ps[0]= new Product(pCode,pName,price);
  27.     ps[1]= new Product(101,"Pencil",12);
  28.     ps[2]= new Product(102,"Pen",10);
  29.     int minprice=ps[0].price;
  30.     System.out.print("\nCODE\tNAME\tPRICE");
  31.     System.out.print("\n____________________");
  32.     for(Product p:ps)
  33.     {
  34.     System.out.print("\n"+p.pCode+"\t"+p.pName+"\t"+p.price);
  35.     if(minprice > p.price)
  36.     {
  37.     minprice=p.price;
  38.     }
  39.     }
  40.     System.out.print("\n____________________");
  41.     System.out.print("\nLowest Cost Product details");
  42.     System.out.print("\n____________________");
  43.     for(Product p:ps)
  44.     {
  45.     if(minprice==p.price)
  46.     {
  47.     System.out.print("\nProduct Code :"+p.pCode);
  48.     System.out.print("\nProduct Name :"+p.pName);
  49.     System.out.print("\nProduct Price:"+p.price);
  50.     }
  51.     }
  52.     }
  53.     }

Raw Paste

Login or Register to edit or fork this paste. It's free.