Deprecated: Function set_magic_quotes_runtime() is deprecated in /DISK2/WWW/lokiware.info/mff/wakka.php on line 35
…aneb může se hodit k testu v labu. (Vzhledem k Hnětynkovým podmínkám je třeba si je vytisknout.) Příklady jsou často převzaté z webu Sunu a lehce upravené.
Zdroj: http://java.sun.com/docs/books/tutorial/essential/io/scanning.html
Deprecated: Assigning the return value of new by reference is deprecated in /DISK2/WWW/lokiware.info/mff/formatters/highlight/java.php on line 5
import java.io.*; import java.util.Scanner; /* ... */ Scanner s = null; try { s = new Scanner(new BufferedReader(new FileReader("slova_oddelena_bilymi znaky.txt"))); while (s.hasNext()) System.out.println(s.next()); } finally { if (s != null) s.close(); }
import java.io.*; import java.util.*; /* ... */ Scanner s = null; double sum = 0; try { s = new Scanner( new BufferedReader(new FileReader("cisla.txt")) ); s.useLocale(Locale.US); while(s.hasNext() ){ if( s.hasNextDouble() ) sum += s.nextDouble(); else s.next(); // ignoruje ne-cisla } } finally { s.close(); } System.out.println(sum);
Zdroj: http://java.sun.com/docs/books/tutorial/uiswing/start/compile.html
Deprecated: Assigning the return value of new by reference is deprecated in /DISK2/WWW/lokiware.info/mff/formatters/highlight/java.php on line 5
import javax.swing.*; public class HelloWorldSwing { /** * Create the GUI and show it. For thread safety, this method * should be invoked from the event-dispatching thread. */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("HelloWorldSwing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add the ubiquitous "Hello World" label. JLabel label = new JLabel("Hello World"); frame.getContentPane().add(label); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
Pozn.: Součástí výše uvedených příkladů z webu Sunu je toto upozornění.