[ASAP] optimized code: max 8 semi colons

Hi

i need help getting rid of semi colons. Do you guys know of any tricks that i can use to get rid of semicolons. Such as initializing a variable without the use of a colon(via some trick). My professor said that is possible. It is also possible to get rid of the i/o import:

I have a impot java.util.*; and a Scanner x = new ... ;

How can I get rid of those 2 semi colons and stil read user input.

Thanks

[437 byte] By [bobDylana] at [2007-11-27 4:36:10]
# 1
You can use the fully qualified classname instead of the import, but you must have some semi colons, and I don't see a reason to try to get rid of them. It just makes the code harder to read.Kaj
kajbja at 2007-7-12 9:46:19 > top of Java-index,Java Essentials,Java Programming...
# 2
?String line = (new Scanner(...)).nextLine(); (or whatever it is)
TuringPesta at 2007-7-12 9:46:19 > top of Java-index,Java Essentials,Java Programming...
# 3
> ?> String line = (new java.util.Scanner(...)).nextLine(); (or> whatever it is)To get rid of the import.
kajbja at 2007-7-12 9:46:19 > top of Java-index,Java Essentials,Java Programming...
# 4
Is the challenge to write a program to do X (what is X?) with at most 8 semicolons in the program?!
Hippolytea at 2007-7-12 9:46:19 > top of Java-index,Java Essentials,Java Programming...
# 5

You could slim down by writing:

int i=17, j=42, k=1066;

instead of

int i = 17;

int j = 42;

int k = 1066;

or by using an array:

int[] vars = {17, 42, 1066};

Hippolytea at 2007-7-12 9:46:19 > top of Java-index,Java Essentials,Java Programming...
# 6
> Such as initializing a variable without the use of a colon(via some trick)int x=0, y=1;is the only such trick which springs to mind.
YAT_Archivista at 2007-7-12 9:46:19 > top of Java-index,Java Essentials,Java Programming...
# 7
Of course you could replace all the semicolons with \u003b !
sabre150a at 2007-7-12 9:46:19 > top of Java-index,Java Essentials,Java Programming...
# 8

how about:

boolean isOptimized() {

return expr ? expr1 : expr2;

}

instead of

boolean isOptimized() {

boolean x;

if (expr)

x = expr1;

else

x = expr2;

return x;

}

Hippolytea at 2007-7-12 9:46:19 > top of Java-index,Java Essentials,Java Programming...
# 9
Sabre is the winner. :)
kajbja at 2007-7-12 9:46:19 > top of Java-index,Java Essentials,Java Programming...
# 10
> Sabre is the winner. :)And I didn't even have to use a regex!
sabre150a at 2007-7-12 9:46:19 > top of Java-index,Java Essentials,Java Programming...
# 11
> > Sabre is the winner. :)> > And I didn't even have to use a regex!I bet you would have used regexp to find all occurences of ; in all files ending with java ;)
kajbja at 2007-7-12 9:46:19 > top of Java-index,Java Essentials,Java Programming...
# 12

> > > Sabre is the winner. :)

> >

> > And I didn't even have to use a regex!

>

> I bet you would have used regexp to find all

> occurences of ; in all files ending with java ;)

:-) Also in in the FileFilter used to select only those files ending in ".java" .

if (file.getName().matches(".*\\.java$")))

{

}

I know I could use String.endsWith() but real men use a regex whenever they can.

sabre150a at 2007-7-12 9:46:19 > top of Java-index,Java Essentials,Java Programming...
# 13
I thought about it a bit more and you can do an arbitrary number of assignments for 2 semicolons with a loop: for (i=3,d=0.5,foo=bar;"".length()>0;) {}
YAT_Archivista at 2007-7-12 9:46:19 > top of Java-index,Java Essentials,Java Programming...