0% found this document useful (0 votes)
1 views5 pages

Java

The document contains Java code snippets demonstrating how to remove specific elements from an array and how to find the longest and shortest films from a list of film objects. It also includes examples of file handling in Java, specifically appending text to a file. Overall, it provides practical coding solutions for common programming tasks.

Uploaded by

shwetikesoe704
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views5 pages

Java

The document contains Java code snippets demonstrating how to remove specific elements from an array and how to find the longest and shortest films from a list of film objects. It also includes examples of file handling in Java, specifically appending text to a file. Overall, it provides practical coding solutions for common programming tasks.

Uploaded by

shwetikesoe704
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

boolean [] deleteItem = new

boolean[[Link]];
int size=0;
for(int i=0;i<[Link];i==){
if(arr[i].equals("a")){
deleteItem[i]=true;
}
else{
deleteItem[i]=false;
size++;
}
}
String[] newArr=new String[size];
int index=0;
for(int i=0;i<[Link];i++){
if(!deleteItem[i]){
newArr[index++]=arr[i];
}
}
answered Sep 22 '08
edited Sep 22 at 12:50
link|flag '08 at 13:06
shsteimer
2,574●9●38

arrgh can't get code to show up correctly.


0
sorry got it working. sorry again i don't
think I read the question properly

String foo[] =
{"a","cc","a","dd"},
remove =
"a";
boolean gaps[] = new
boolean[[Link]];
int newlength = 0;

for(int c =
0;c<[Link];c++)
{

if(foo[c].equals(remove))
{
gaps[c] =
true;
newlength+
+;
}
else gaps[c] =
false;
[Link](foo[c]);
}

String newString[] = new


String[newlength];

[Link]("");

for(int c1=0,c2=0
;c1<[Link];c1++)
{
if(!gaps[c1])
{

newString[c2] = foo[c1];

[Link](newString[c2]);
c2++;
}
}
Object

public class Weekend {

public static void main(String [] args) {

// Set up a series of film objects

Film Watch[] = new Film[4];


Watch[0] = new Film("Shrek",133);
Watch[1] = new Film("Road to Perdition",117);
Watch[2] = new Film("The Truth about Cats and Dogs",93);
Watch[3] = new Film("Enigma",114);

Film Longest = null, Shortest = null; // To avoid a grumpy compiler


int longtime = 0, shorttime = 0; // To avoid a grumpy compiler

for (int i=0; i<[Link]; i++) {


int mins = Watch[i].getminutes();
if (i == 0) {
Shortest = Longest = Watch[i];
shorttime = longtime = mins;
} else {
if (mins < shorttime) {
shorttime=mins;
Shortest = Watch[i];
}
if (mins > longtime) {
longtime=mins;
Longest = Watch[i];
}
}
}
[Link]("Longest film is " +
[Link]() +
" at "+longtime+" minutes");
[Link]("Shortest film is " +
[Link]() +
" at "+shorttime+" minutes");
}
}
hi james

solution is

child [] children=new child[5];


classname[] arrayname=new classname[no of objects];
then u write

child[0]=new child(23);
classname[objectnumber]=new classname(age);

child(23) is a parameterized construtor of class child.

this should solve ur problem...


do let me know when ur done
File Save DAT file

try
{
String filename= "[Link]";
boolean append = true;
FileWriter fw = new FileWriter(filename,append);

[Link]("add a line\n");//appends the string to the file


[Link]();
}

catch(IOException ioe)
{
[Link]("IOException: " + [Link]());
}

You might also like