Array of Objects

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

import java.util.

Scanner;
class Book
{
String name;
int id;
Boolean check( String
bname)
{
boolean result = false;
if(name.equals(bname))
{
System.out.println("yes");
result = true;
}
else
{
System.out.println("No");
result = false;
}
return result;}
public static void main(String
args[])
{Scanner in = new
Scanner(System.in);
String ch="B";

Book[] bookArray = new


Book[3];
for ( int i=0;
i<bookArray.length; i++)
{
bookArray[i]=new Book();
}
for(int i=0;
i<bookArray.length; i++)
{
System.out.println("Enter
book name ");
bookArray[i].name=
in.nextLine();
}
for(int i=0;
i<bookArray.length; i++)
{
System.out.println("Enter
book id");
bookArray[i].id=in.nextInt
();
}
for(int i=0;
i<bookArray.length; i++)
{Boolean s=
bookArray[i].check(ch);
if(s)
break; }}}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy