Source code |
|
1 2 3 4 5 6 7 |
class Test { public static void main(String... args) { double test; test = 4/3.0; System.out.printf("%.1g", test); } } |
This post has been edited 1 times, last edit by "maffe" (Apr 22nd 2006, 1:45pm)
Alter Hase
Date of registration: Oct 9th 2002
Location: Zimbabwe-Island Ost Beiträge: 3.427
Occupation: Informatiker
Quoted
Original von rad
System.out.printf("%.1f", test);
http://java.sun.com/j2se/1.5.0/docs/api/…ter.html#syntax
Quoted
Original von Ray-D
die zahl multiplizieren mit 10^a, wobei a die anzahl der nachkommastellen ist, dann runden und dann wieder durch 10^a dividieren. beispiel:
4/3 = 1.3333333333
1.333333333* 10^1 = 13.3333333333
Math.round(13.33333333333333) = 13
13 / 10^1 = 1.3
jetzt daraus eine schöne methode machen
Quoted
Original von rad
System.out.printf("%.1f", test);
Quoted
Original von ktm
Ray-D: Als Scherz gedacht, oder ganz einfach gePwned worden?
Deine erste Programmiersprache? So ne Formatierungsfunktion gibts doch eigentlich -überall-...
Alter Hase
Date of registration: Oct 9th 2002
Location: Zimbabwe-Island Ost Beiträge: 3.427
Occupation: Informatiker
Quoted
Original von ktm
Ray-D: Als Scherz gedacht, oder ganz einfach gePwned worden?
Deine erste Programmiersprache? So ne Formatierungsfunktion gibts doch eigentlich -überall-...
Quoted
Master Foo once said to a visiting programmer: “There is more Unix-nature in one line of shell script than there is in ten thousand lines of C.”
The programmer, who was very proud of his mastery of C, said: “How can this be? C is the language in which the very kernel of Unix is implemented!”
Master Foo replied: “That is so. Nevertheless, there is more Unix-nature in one line of shell script than there is in ten thousand lines of C.”
The programmer grew distressed. “But through the C language we experience the enlightenment of the Patriarch Ritchie! We become as one with the operating system and the machine, reaping matchless performance!”
Master Foo replied: “All that you say is true. But there is still more Unix-nature in one line of shell script than there is in ten thousand lines of C.”
The programmer scoffed at Master Foo and rose to depart. But Master Foo nodded to his student Nubi, who wrote a line of shell script on a nearby whiteboard, and said: “Master programmer, consider this pipeline. Implemented in pure C, would it not span ten thousand lines?”
The programmer muttered through his beard, contemplating what Nubi had written. Finally he agreed that it was so.
“And how many hours would you require to implement and debug that C program?” asked Nubi.
“Many,” admitted the visiting programmer. “But only a fool would spend the time to do that when so many more worthy tasks await him.”
“And who better understands the Unix-nature?” Master Foo asked. “Is it he who writes the ten thousand lines, or he who, perceiving the emptiness of the task, gains merit by not coding?”
Upon hearing this, the programmer was enlightened.
- http://www.catb.org/~esr/writings/unix-k…n-thousand.html
This post has been edited 1 times, last edit by "ktm" (Apr 23rd 2006, 7:30am)
Zerschmetterling
Date of registration: Aug 31st 2003
Location: Hannover
Occupation: Informatikstudent (d'uh)
This post has been edited 1 times, last edit by "hamena314" (Apr 24th 2006, 9:06am)
Guru
Date of registration: Dec 11th 2001
Location: Hämelerwald
Occupation: Wissenschaftlicher Mitarbeiter (Forschungszentrum L3S, TU Braunschweig)
Hab mir die Aufgabe gerade mal angeschaut.Quoted
Original von hamena314
P.S.: Hat jemand einen guten Vorschlag für Aufgabe 2?
Wollte die nachher erst noch machen und hatte bisher nur die Idee 3er ineinander verschachtelter for-Schleifen. =)
Guru
Date of registration: Dec 11th 2001
Location: Hämelerwald
Occupation: Wissenschaftlicher Mitarbeiter (Forschungszentrum L3S, TU Braunschweig)
Elegant finde ich das nicht, weil eine solche Konstruktion nicht auf Wahrheitstabellen für größere Variablenanzahlen verallgemeinert werden kann. Mit Deinem Vorgehen müßte sich nämlich der Quellcode für jede Anzahl von Variablen ändern. (Hier sind zwar nur drei Variablen vorhanden, aber es könnten genauso gut fünf oder zehn sein.)Quoted
Original von Alucard
Hab bei Aufgabe2 3 verschachtelte Do-Schleifen genommen.
Für jede Variable a,b,c eine Schleife wobei nach jeder Schleife der jeweilige boolsche-Wert negiert wird.
In der letzten Schleife dann zusätzlich noch die Ausgabe der Verknüpfungen.
Hatten das zwar noch nich in der Vorlesung is aber kurz und elegant.
This post has been edited 1 times, last edit by "Joachim" (Apr 24th 2006, 11:26am)
Guru
Date of registration: Dec 11th 2001
Location: Hämelerwald
Occupation: Wissenschaftlicher Mitarbeiter (Forschungszentrum L3S, TU Braunschweig)
Ups, das habe ich überlesen.Quoted
Original von BLUESCREEN
Quoted
Original von Joachim
Eine elegantere (aber auch aufwendigere) Lösung wäre es, mit einer for-Schleife zu arbeiten, die von 0 bis 2^3 - 1 zählt.
Laut Aufgabenstellung soll man mehrere verschachtelte Schleifen verwenden.
This post has been edited 1 times, last edit by "sos1981" (Apr 24th 2006, 10:02pm)
This post has been edited 1 times, last edit by "julianr" (Apr 24th 2006, 11:11pm)
Trainee
Date of registration: Oct 12th 2005
Location: Hildesheim
Occupation: B.Sc. Informatik / 1. Semester