Code java couramment utilisé

«Je dois créer un améliorée pour déclaration. Quelqu'un peut me rappeler comment coder un améliorée pour déclaration? Et pendant que vous y êtes, comment puis-je attraper une exception? Où puis-je trouver tout ce que Java choses rapidement? "




Vous trouverez tout ça ici, dans cette feuille de triche. Le programme Java dans cette feuille de triche contient des extraits de code représentant un grand nombre de caractéristiques linguistiques les plus importants de Java, y compris les commutateurs, les cordes, les pauses, si. . . autre déclarations, et les tableaux. Comme un bonus supplémentaire, le programme contient même une référence sournoise à ce classique des Marx Brothers film, Animal Crackers. Profitez!

CheatSheet classe package com.example.cheetsheet-import-import javax.swing.JOptionPane java.util.ArrayList public {int myInt = 42 double myDouble = myBoolean 27649,00-Boolean = true-public static void main (String [] args) {nouvelle CheatSheet () -} CheatSheet publique () {char myChar = 'B' String myString = "Bonjour" -ArrayList myList = new ArrayList() -string [] MyArray = {"Cette", "est", "un", "tableau". } -System.out.println (MyInt) -System.out.println (myChar) -JOptionPane.showMessageDialog (null, myString) -System.out.println (myInt + "" + myString + "" + myDouble) -string Stringin = JOptionPane.showInputDialog ("Entrez un nombre de 1 à 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 ("Oui") -} interrupteur (myInt) {case 1: System.out.println ("One") - briser cas 2: 3 cas: System.out.println ("Un petit nombre") - briser par défaut: System.out.println («beaucoup» ) -break-} for (int i = 0 à i lt; 10- i ++) {System.out.print (i) -System.out.print ("") -} System.out.println () - int i = 0-tout (i lt; 10) {System.out.print (i ++ + "") -} System.out.println () - int j = 0-do {System.out.print (j ++) - System.out.print (j lt; = 9 ",": "") -} while (j? lt; 10) -System.out.println () - myList.add ("Trois") -myList.add ("Cheers") -myList.add («pour») -myList.add ("capitaine") -myList.add ("Spaulding") - pour (String mot: myList) {System.out.print (mot) -} System.out.println () - System.out.println (addPeriod ("Spaulding")) - for (int n = 0- n lt; myArray.length- n ++) {System.out.print (myArray [n]) -} System.out.println () -} Chaîne addPeriod (chaîne String) {return de chaîne + "." -}}

» » » » Code java couramment utilisé