Kytcs.Blogspot.com: Java Arrays - Hands on 1 Problem 1

Java Arrays - Hands on 1 Problem 1

Java Arrays - Hands on 1
Problem 1:


_______________________________________________________________

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String args[] ) throws Exception {
Scanner sc=new Scanner(System.in);
Document[] docsArray=new Document[4];
Document[] res=new Document[4];
for(int i=0;i<docsArray.length;i++)
{
docsArray[i]=new Document();
res[i]=new Document();
}
for(int i=0;i<docsArray.length;i++)
{
docsArray[i].id=sc.nextInt();
docsArray[i].title=sc.next();
docsArray[i].folderName=sc.next();
docsArray[i].pages=scn.nextInt();
}
res= docsWithOddPages(docsArray);
for(int i=0;i<res.length;i++)
{
if(res[i].title!=null)
System.out.println(res[i].id+" "+res[i].title+" "+res[i].folderName+" "+res[i].pages);
}
}
public static Document[] docsWithOddPages(Document[]docsArray){
Document[] oddDocs=new Document[4];
for(int i=0;i<docsArray.length;i++)
{

oddDocs[i]=new Document();
}
int k=0;
for(int i=0;i<docsArray.length;i++)
{
if(docsArray[i].pages%2!=0)
{
oddDocs[k++]=docsArray[i];
}
}
return oddDocs;
}
}
class Document
{
int id,pages;
String title,folderName;
}

No comments:

Post a Comment

Followers

Ad Space