0% found this document useful (0 votes)
17 views

Docs With Odd Pages

java pratice question

Uploaded by

ppatil20comp
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Docs With Odd Pages

java pratice question

Uploaded by

ppatil20comp
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Create class Document with below attributes

id - int
title - String
folderName - String
pages - int

Write getters, setters and parameterized constructor as required.

Create class Solution with main method.

Implement static method - docsWithOddPages in Solution class.

This method will take array of Document objects and return another array with
Document objects which has odd number of pages.

This method should be called from main method and display values of returned
objects as shared in the sample (in ascending
order of id attribute).

Before calling this method, use Scanner object to read values for four Document
objects referring attributes in the above
sequence.

Next call the method and display the result.

Consider below sample input and output:

Input:
1
resume
personal
50
2
question1
exams
55
3
question2
exams
45
4
India
misc
40

Output (each line has values separated by single space):


2 question1 exams 55
3 question2 exams 45

Note on using Scanner object:


Sometimes scanner does not read the new line character while invoking methods like
nextInt(), nextDouble() etc.
Usually, this is not an issue, but this may be visible while calling nextLine()
immediately after those methods.
Consider below input values:
22
hello

Referring below code:

Scanner sc = new Scanner(System.in);


int x = sc.nextInt();
String str = sc.nextLine(); -> here we expect str to have value hello. Instead it
may be """".

If above issue is observed, then it is suggested to add one more explicit call to
nextLine() after reading numeric value.

You might also like