Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Treue Seele
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Reader reader = null; try { reader = new FileReader( "bin/lyrics.txt" ); for ( int c; ( c = reader.read() ) != –1; ) System.out.print( (char) c ); } catch ( IOException e ) { System.err.println( "Fehler beim Lesen der Datei!" ); } finally { try { reader.close(); } catch ( Exception e ) { } } |
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
package lesen; import java.io.*; import java.util.*; public class AP02 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub double [][] preise = new double[][]{{0.35,1.09,0.45},{0.42,1.23,0.62},{0.46,1.34,0.87},{0.49,1.46,0.91}}; Date a = new Date(); Date b = new Date(); double diff=0; int anzahl=0; int jahr=0; int monat=0; int tag=0; int stunde=0; int minute=0; int sekunde=0; double gesamt=0; int x = -1; int y = -1; try{ StreamTokenizer eingabe = new StreamTokenizer(System.in); System.out.println("Dateiname eingeben:"); eingabe.nextToken(); String s1 = eingabe.sval; String pfad = "C:\\Users\\Wolfgang\\workspace\\Dateizugriff\\bin\\lesen\\"+s1; FileReader datei = new FileReader(pfad); eingabe = new StreamTokenizer(datei); eingabe.nextToken(); while(eingabe.ttype != StreamTokenizer.TT_EOF){ if(eingabe.ttype == StreamTokenizer.TT_NUMBER){ int wert = (int)eingabe.nval; String text = String.valueOf(wert); if(text.length()==8){ jahr = Integer.parseInt(text.substring(0,4)); monat = Integer.parseInt(text.substring(4,6)); tag = Integer.parseInt(text.substring(6,8)); //System.out.println("jahr:"+jahr); //System.out.println("monat:"+monat); //System.out.println("tag:"+tag); } if(text.length()==6){ stunde = Integer.parseInt(text.substring(0,2)); minute = Integer.parseInt(text.substring(2,4)); sekunde = Integer.parseInt(text.substring(4,6)); //System.out.println("stunde:"+stunde); //System.out.println("minute:"+minute); //System.out.println("sekunde:"+sekunde); } anzahl++; if(anzahl == 2){ a = new Date(jahr-1900,monat-1,tag,stunde,minute,sekunde); //System.out.println(a); } if(anzahl == 4){ b = new Date(jahr-1900,monat-1,tag,stunde,minute,sekunde); } }else{ String text = eingabe.sval; //System.out.println("rechner:"+text); if(a.getHours() > 0){ y = 0; } if(a.getHours() > 6){ y = 1; } if(a.getHours() > 18){ y = 2; } if(text.equals("A")){ x = 0; }else if(text.equals("B")){ x = 1; }else if(text.equals("C")){ x = 2; }else if(text.equals("D")){ x = 3; } //System.out.println("x:"+x+" / y:"+y); diff = b.getTime() - a.getTime(); diff = diff / 1000; //System.out.println("diff:"+diff); //System.out.println("preis:"+preise[x][y]); gesamt += ( diff * preise[x][y]); //System.out.println(diff+" Sekunden an Rechnertyp "+text); anzahl = 0; } eingabe.nextToken(); } }catch(Exception e){ System.out.println("Fehler: "+e); } System.out.printf("Die Kosten betragen %.2f €",gesamt); } } |
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »Chromanoid« (02.11.2011, 14:08)
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
private Date readDate(StreamTokenizer eingabe) throws Exception { eingabe.nextToken(); if(eingabe.ttype == StreamTokenizer.TT_EOF) return null; String text = String.valueOf((int)eingabe.nval); eingabe.nextToken(); text += String.valueOf((int)eingabe.nval); if(text.length!=14) throw Exception("Ungültiges Datum in Zeile "+eingabe.lineno()); int jahr = Integer.parseInt(text.substring(0,4))-1900; int monat = Integer.parseInt(text.substring(4,6))-1; int tag = Integer.parseInt(text.substring(6,8)); int stunde = Integer.parseInt(text.substring(8,10)); int minute = Integer.parseInt(text.substring(10,12)); int sekunde = Integer.parseInt(text.substring(12,14)); return new Date(jahr,monat,tag,stunde,minute,sekunde); } |
Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von »Chromanoid« (02.11.2011, 14:07)
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »JoeChip« (02.11.2011, 15:12)
Werbeanzeige