Código usados ​​Java

"Eu tenho que criar uma melhorada para declaração. Alguém pode me lembrar como codificar uma melhorada para declaração? E enquanto você está nisso, como eu posso pegar uma exceção? Onde posso encontrar todas as coisas que Java rapidamente? "

Você encontra tudo isso bem aqui nesta folha de fraude. O programa Java nesta folha de fraude contém trechos de código que representa muitos dos recursos de linguagem mais importantes do Java, incluindo switches, cordas, intervalos, E se . . . outro declarações e matrizes. Como um bônus adicional, o programa contém ainda uma referência irônica ao clássico filme dos irmãos Marx, Animal Crackers. Apreciar!

classe CheatSheet pacote com.example.cheetsheet-import java.util.ArrayList-import javax.swing.JOptionPane-pública {int myInt = 42-double myDouble = 27649,00-boolean myBoolean = true-public void main (String [] args) estáticos {new CheatSheet () -} CheatSheet pública () {char MyChar = 'B'-string myString = "Olá" -ArrayList myList = new ArrayList() -String [] MyArray = { "Isso", "é", "um", "matriz". } -System.out.println (MyInt) -System.out.println (MyChar) -JOptionPane.showMessageDialog (null, myString) -System.out.println (myInt + "" + minhaString + "" + myDouble) -String stringIn = JOptionPane.showInputDialog ( "Introduza um número de 1 a 10") - try {myInt = Integer.parseInt (stringIn) -} catch (NumberFormatException e) {e.printStackTrace () -} if (myInt lt; 5) {System.out.println ( "Small") -} else {System.out.println ( "Large") -} if (myBoolean) {System.out.println ( "Sim") -} switch (myInt) {case 1: System.out.println ( "One") - break-case 2: case 3: System.out.println ( "Um pequeno número") - break-padrão: System.out.println ( "muito" ) -break-} for (int i = 0- i lt; 10- i ++) {System.out.print (i) -System.out.print ( "") -} System.out.printlnl () - int i = 0-tempo (i lt; 10) {System.out.println (i ++ + "") -} System.out.println () - int j = 0-do {System.out.println (j ++) - System.out.print (j lt; = 9 ",": "") -} enquanto (J? lt; 10) -System.out.println () - myList.add ( "Three") -myList.add ( "Cheers") -myList.add ( "de") -myList.add ( "Captain") -myList.add ( "Spaulding") - para (string palavra: myList) {System.out.println (word) -} System.out.println () - System.out.println (addPeriod ( "Spaulding")) - para (int n = 0- n lt; myArray.length- n ++) {System.out.println (myArray [n]) -} System.out.println () -} Cadeia addPeriod (string String) {return cadeia + "." -}}

menu