Last active
August 20, 2018 06:24
-
-
Save dheysonalves/66eef8935728646addbc5fd783c2afe5 to your computer and use it in GitHub Desktop.
br.com.myjavag.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Break { | |
public static void main(String[] args) { | |
labelForI: for (int i = 0; i < 10; i++) { | |
for (int j = 0; j < 10; j++) { | |
if(j==5 && i==3){ | |
break labelForI; | |
} | |
System.out.println("O valor de i é:"+i+" O valor de j é:"+j); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
/** | |
* | |
* @author DHEYSON | |
*/ | |
public class Bubble { | |
public static void main(String[] args) { | |
int [] nums = { 99, -10 , 100123, 18, -978, | |
5623, 463, -9, 287, 49 }; | |
int a,b,t; | |
int size; | |
size = 10; | |
System.out.print("Original array is:"); | |
for (int i = 0; i < size; i++) { | |
System.out.print(" " + nums[i]); | |
} | |
for (a = 1; a < size; a ++) { | |
for (b = size-1;b >= a; b--) { | |
if (nums[b-1] > nums[b]) { | |
t = nums[b-1]; | |
nums[b-1] = nums[b]; | |
nums[b] = t; | |
} | |
} | |
} | |
System.out.print("\nSorted array is:"); | |
for (int i = 0; i < size; i++) { | |
System.out.print(" " + nums[i]); | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OperadorCurtoCircuito { | |
public static void main(String[] args) { | |
int n,d,q; | |
n=10; | |
d=2; | |
if (d != 0 && (n % d) == 0) { | |
System.out.println(d + " é um fator de " + n); | |
} | |
d=0; | |
if (d != 0 && (n % d) == 0) { | |
System.out.println(d + " é um fator de" + n); | |
} | |
if (d != 0 & (n % d) == 0) { // as duas operações são avaliadas, permitindo uma divisão por 0 | erro de tempo de execução | |
System.out.println(d + "é um fator de" + n); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
import java.util.Scanner; | |
public class NumerosAleatorios { | |
public static void main(String[] args) { | |
Random num = new Random(); | |
int num1=2; | |
int num2=4; | |
Scanner x = new Scanner(System.in); | |
System.out.println(num.nextInt(6)+1); | |
System.out.println(num.nextDouble()*20); | |
String valor = (num1>num2) ? "verdadeiro" : "falso"; | |
System.out.println(valor); | |
System.out.println("Qual o dia da semana?"); | |
System.out.println("Digite 1 para segunda e 7 para domingo"); | |
int num3 = x.nextInt(); | |
String dia = (num3==1) ? "segunda" : | |
(num3==2) ? "terça" : | |
(num3==3) ? "quarta" : | |
(num3==4) ? "quinta" : | |
(num3==5) ? "sexta" : | |
(num3==6) ? "sábado" : | |
(num3==7) ? "domingo" : | |
"dia inválido"; | |
System.out.println("O dia escolhido foi:" + dia); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment