Diferencia entre revisiones de «Usuario:Lmorillas/modulo programacion/java/ejemplos»
De WikiEducator
< Usuario:Lmorillas | modulo programacion | java
(Página creada con '{{MiTitulo| Ejemplos Java}} == Hola mundo == <source lang="python"> print "Hello World!" </source> <source lang="java"> public class Hello { public static void main(Strin…') |
|||
(Una revisión intermedia por el mismo usuario no mostrado) | |||
Línea 3: | Línea 3: | ||
== Hola mundo == | == Hola mundo == | ||
+ | En python: | ||
<source lang="python"> | <source lang="python"> | ||
print "Hello World!" | print "Hello World!" | ||
</source> | </source> | ||
− | + | En java: | |
<source lang="java"> | <source lang="java"> | ||
public class Hello { | public class Hello { | ||
public static void main(String[] args) { | public static void main(String[] args) { | ||
System.out.println("Hello World!"); | System.out.println("Hello World!"); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | == Ejemplo de lectura con Scanner == | ||
+ | <source lang="java"> | ||
+ | import java.util.Scanner; | ||
+ | |||
+ | public class TempConv { | ||
+ | public static void main(String[] args) { | ||
+ | Double fahr; | ||
+ | Double cel; | ||
+ | Scanner in; | ||
+ | |||
+ | in = new Scanner(System.in); | ||
+ | System.out.println("Enter the temperature in F: "); | ||
+ | fahr = in.nextDouble(); | ||
+ | |||
+ | cel = (fahr - 32) * 5.0/9.0; | ||
+ | System.out.println("The temperature in C is: " + cel); | ||
+ | |||
+ | System.exit(0); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | == Ejemplo con swing == | ||
+ | <source lang="java"> | ||
+ | import javax.swing.*; | ||
+ | |||
+ | public class TempConvGUI { | ||
+ | |||
+ | public static void main(String[] args) { | ||
+ | String fahrString; | ||
+ | Double fahr, cel; | ||
+ | |||
+ | fahrString = JOptionPane.showInputDialog("Enter the temperature in F"); | ||
+ | fahr = new Double(fahrString); | ||
+ | cel = (fahr - 32) * 5.0/9.0; | ||
+ | |||
+ | JOptionPane.showMessageDialog(null,"The temperature in C is, " + cel); | ||
} | } | ||
} | } | ||
</source> | </source> |
Última revisión de 21:08 2 mar 2012
Hola mundo
En python:
print "Hello World!"
En java:
public class Hello { public static void main(String[] args) { System.out.println("Hello World!"); } }
Ejemplo de lectura con Scanner
import java.util.Scanner; public class TempConv { public static void main(String[] args) { Double fahr; Double cel; Scanner in; in = new Scanner(System.in); System.out.println("Enter the temperature in F: "); fahr = in.nextDouble(); cel = (fahr - 32) * 5.0/9.0; System.out.println("The temperature in C is: " + cel); System.exit(0); } }
Ejemplo con swing
import javax.swing.*; public class TempConvGUI { public static void main(String[] args) { String fahrString; Double fahr, cel; fahrString = JOptionPane.showInputDialog("Enter the temperature in F"); fahr = new Double(fahrString); cel = (fahr - 32) * 5.0/9.0; JOptionPane.showMessageDialog(null,"The temperature in C is, " + cel); } }