�������� ���������������� System.out.println("5.5 .println("5.5 elevado a 2 = " + " + Math. pow (base,potencia)); (base,potencia)); System.out.println("25 .println("25 elevado a 0.5 = " " + + Math. pow (25,.5)); (25,.5)); System.out.println("5678 .println("5678 elevado a 0 = " + " + Math. pow (5678,0)); (5678,0)); } }
������ ���� class ArreProx {
public static void main (String args[]) main {
double a = 5.2, b = 5.6, c = -5.8; System.out.println("Arredondando .println("Arredondando 5.2 Math.ceil(a)); System.out.println("Arredondando .println("Arredondando 5.6 Math.ceil(b)); System.out.println("Arredondando .println("Arredondando -5.8 Math.ceil(c)); } }
= " +
������ ������
= " + = " +
class Aleatorio {
public static void main (String args[]) main {
for(int qtd=1;qtd<=5;qtd++) {
������ �����
for(int x=1;x<=6;x++) {
class ArreAnt
int num = ( int) (Math.random() * 100);
{
System.out.print(num + " } System.out.println();
public static void main (String args[]) main {
double a = 5.2, b = 5.6, c = -5.8; System.out.println("Arredondando .println("Arredondando 5.2 Math.floor (a)); (a)); System.out.println("Arredondando .println("Arredondando 5.6 Math.floor (b)); (b)); System.out.println("Arredondando .println("Arredondando -5.8 Math.floor (c)); (c)); } }
");
}
= " +
} }
= " +
������ �������������
= " +
import java.text.DecimalFormat; class FormatNumeros {
public static void main(String args[]) main(String
������ ���
{ DecimalFormat df = new DecimalFormat(); short idade = 38; df.applyPattern("000" df.applyPattern( "000"); ); System.out.println("Idade .println("Idade : " + df.format(idade));
class MaiorValor {
public static void main (String args[]) main {
int a = 10, b = 15; double c = -5.9, d = -4.5;
int quantidade = 9750;
System.out.println("O .println("O maior entre 10 e 15 = " + Math.max (a,b)); (a,b)); System.out.println("O .println("O maior entre -5.9 e -4.5 = " + " + Math.max (c,d)); (c,d)); System.out.println("O .println("O maior entre 10 e -5.9 = " + Math.max (a,c)); (a,c)); } }
df.applyPattern("#0,000" df.applyPattern( "#0,000"); ); System.out.println("Quantidade .println("Quantidade : " + " + df.format(quantidade));
long estoque = 198564; df.applyPattern("#,##0,000" df.applyPattern( "#,##0,000"); ); System.out.println("Estoque .println("Estoque df.format(estoque));
: " +
float altura = 1.74f;
������ ���
df.applyPattern("#0.00" df.applyPattern( "#0.00"); ); System.out.println("altura .println("altura
class MenorValor
double peso = 70.25;
{
df.applyPattern("#0.00" df.applyPattern( "#0.00"); ); System.out.println("Peso .println("Peso
public static void main (String args[]) main
: " + df.format(altura));
: " + df.format(peso));
{
int a = 10, b = 15; double c = -5.9, d = -4.5; System.out.println("O .println("O menor entre 10 e 15 = " + Math.min(a,b)); System.out.println("O .println("O menor entre -5.9 e -4.5 = " + " + Math.min(c,d)); System.out.println("O .println("O menor entre 10 e -5.9 = " + Math.min(a,c)); } }
String valorEmReais = "2583.75" "2583.75"; ; df.applyPattern("R$ df.applyPattern( "R$ #,##0.00"); #,##0.00"); System.out.println("Valor .println("Valor em Reais: " + " + df.format(Double. parseDouble(valorEmReais))); } }
������ ������ ������ ���� import java.text.DecimalFormat; import java.util.Locale;
class RaizQuadrada {
class Internacionalizacao
public static void main (String args[]) main
{
{
public static void main(String args[]) main(String
double a = 900, b = 30.25; System.out.println("A .println("A raiz quadrada de 900 Math.sqrt(a)); System.out.println("A .println("A raiz quadrada de 30.25 Math.sqrt(b)); } }
������ ��� class Potencia {
public static void main (String args[]) main {
double base = 5.5, potencia = 2;
= " + = " + " +
{ DecimalFormat df = new DecimalFormat(); Locale local = Locale. getDefault (); System.out.println("Configuracoes .println("Configuracoes do Sistema Operacional:"); Operacional:" ); System.out.println("Sigla: .println("Sigla: " + " + local.getCountry()); System.out.println("Pais: .println("Pais: " + " + local.getDisplayCountry()); System.out.println("Idioma: .println("Idioma: " + " + local.getDisplayLanguage()); System.out.println("Teclado: .println("Teclado: " + " + local.getDisplayName()); System.out.println("" .println(""); ); double valor = 1370.25; if (local.getCountry().equals( (local.getCountry().equals("BR" "BR")) )) { df.applyPattern("R$ df.applyPattern( "R$ #,##0.00"); #,##0.00"); } System.out.println("valor: .println("valor: " + " + df.format(valor));
} }
Método trim class RemoveEspacos
������ ������ class TamanhoString {
public static void main (String args[]) { String frase = "Aprendendo Java"; int tamanho; tamanho = frase.length(); System.out.println("String: " + frase); System.out.println("Tamanho da string = " + tamanho);
{
public static void main (String args[]) { String frase = " Jesus Cristo: o rei dos reis. "; System.out.println("Com espacos: " + "*" + frase + "*"); System.out.println("Sem espacos: " + "*" + frase.trim() + "*"); } }
} }
Método replace class SubstCaracteres {
Método chaAt
public static void main (String args[]) {
class RetornaCaractere {
public static void main (String args[]) { String frase = "Aprendendo Java"; System.out.println("String = " + frase); System.out.println("Caracter = " + frase.charAt(5)); System.out.print("Trecho = "); for (int i=11;i<=14;i++) { System.out.print(frase.charAt(i)); } System.out.println();
String frase1 = "o macaco gosta de banana"; String frase2 = frase1.replace(" ",""); System.out.println("Frase 1: " + frase1); System.out.println("Frase 2: " + frase2); System.out.println("Frase 3: " + frase1.replace(" ", "_")); System.out.println("Frase 4: " + frase1.replace("a", "u")); System.out.println("Frase 5: " + frase1.replace("na", "NA")); } }
} }
������ �������
Métodos toUpperCase e toLowerCase
class ConverteDados {
public static void main (String args[]) { String x = "";
class MaiMinusculas
int a = 11; long b = 222; float c = 3333; double d = 4.444;
{
public static void main (String args[]) { String palavra = "LINGUAGEM JAVA"; System.out.println(palavra.substring(10,14)); String palavra1 = "ARROZ", palavra2 = "batata"; System.out.println("ARROZ em min£scula = " + palavra1.toLowerCase()); System.out.println("batata em mai£scula = " + palavra2.toUpperCase()); System.out.println("SaLaDa em min£scula = " + "SaLaDa".toLowerCase()); } }
x = x + String. valueOf (a) + x = x + String. valueOf (b) + x = x + String. valueOf (c) + x = x + String. valueOf (d); System.out.println("Valores System.out.println(x);
" - "; " - "; " - "; convertidos:");
} }
MétodoindexOf Método substring class CopiaCaracteres {
public static void main (String args[]) { String frase = "Eu gosto de java!"; System.out.println("Separando uma frase em palavras:"); System.out.println("Palavra 1: " + frase.substring(0,2)); System.out.println("Palavra 2: " + frase.substring(3,8)); System.out.println("Palavra 3: " + frase.substring(9,11)); System.out.println("Palavra 4: " + frase.substring(12)); } }
class LocalizaCaracteres {
public static void main (String args[]) { String texto = "Livro Java 2 - Ensino didatico";
char caractere = 'a'; System.out.println("indice: texto.indexOf(caractere)); System.out.println("indice: texto.indexOf(caractere,10)); System.out.println("indice: texto.indexOf("Ensino")); System.out.println("indice: texto.indexOf("Java",15)); } }
" + " + " + " +