import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
boolean for_demitido=true;
boolean chegarei_cedo=for_demitido;
System.out.println("chegarei_cedo = " + chegarei_cedo);
Scanner sc = new Scanner (System.in);
int temperatura = sc.nextInt();
boolean estiver_quente = temperatura>=27;
boolean nao_tiver_tarefas = false;
nao_tiver_tarefas = for_demitido;
boolean vou_aa_praia = estiver_quente & nao_tiver_tarefas;
System.out.println ("vou_aa_praia =" +vou_aa_praia);
if (vou_aa_praia) {
System.out.println ("#partiupraia");
} else {
System.out.println ("#Ebahcasa!");
}
}
}
Este é o blog de relacionamento com alunos de Fábio Nakano.
Desejo testar se esta mídia facilita a comunicação e aprendizado de conteúdo.
Gostaria que vocès dessem notas mais altas para posts que ajudaram mais a entender o assunto (e não por outro critério, por exemplo o melhor escrito ou o mais "bonito")
fabionakano at usp dot br
Prédio A1, segundo andar - Sala 204E
Caso precise do mapa do Campus:http://each.uspnet.usp.br/site/mapa.php
Siga-me por email preenchendo a caixa abaixo.
Mostrando postagens com marcador ACH2001. Mostrar todas as postagens
Mostrando postagens com marcador ACH2001. Mostrar todas as postagens
sexta-feira, 16 de março de 2018
quinta-feira, 25 de maio de 2017
Objeto No para implementar a Lista Ligada.
public class No { int valor; String payload; No prox; No (int valor, String payload) { this.valor=valor; this.payload=payload; } }
Implemente a interface Busca usando busca binária.
public interface Busca { /**retorna o indice do elemento que contém o valor buscado.*/ int busca (int valorBuscado); }
Implemente a interface Dicionario usando uma lista ligada
public interface Dicionario { /** Insere como primeiro elemento da lista. */ void insere (int valor, String payload); /** Remove o elemento que contém o valor buscado, retorna o payload. * Não pode "quebrar" a lista. */ String remove (int valorBuscado); /** Busca o valor, retorna o payload ou null caso não encontre. */ String busca (int valorBuscado); /** Imprime os elementos da lista. */ void print (); }
quinta-feira, 4 de maio de 2017
código 2 aula de 04.05.2017 turma 3
import java.util.Random; // one class needs to have a main() method public class Penalti { static int placarJogador = 0; static int placarGoleiro = 0; static int[][] gol = new int[3][5]; static void imprimeGol() { System.out.println(); for(int i=0; i < gol.length; i++) { for(int j=0; j < gol[import java.lang.Math; // headers MUST be above the first class i].length; j++) { System.out.print(gol[i][j] + " "); } System.out.println(); } System.out.println("PLACAR = JOGADOR " + placarJogador + " GOLEIRO " + placarGoleiro); } static void limpaGol() { for(int i=0; i < gol.length; i++) { for(int j=0; j < gol[i].length; j++) { gol[i][j] = 0; } } } static boolean defendeu(Jogador j, Goleiro g) { if(g.coluna == j.coluna) { System.out.println("DEFENDEU"); placarGoleiro++; return true; } System.out.println("GOOOL"); placarJogador++; return false; } public static void main(String[] args) { imprimeGol(); Jogador rafinha = new Jogador(); for (int i=0;i<5;i++) { //rafinha.chuta(0,0); rafinha.chuta(); imprimeGol(); Goleiro cassio = new Goleiro(); //cassio.defende(0,0); cassio.defende(); imprimeGol(); defendeu(rafinha, cassio); imprimeGol(); limpaGol(); } } } public class Jogador { // int[][] gol = Penalti.gol; int linha; int coluna; String nome; void chuta (int linha, int coluna) { this.linha = linha; this.coluna = coluna; Penalti.gol[linha][coluna] = 1; } void chuta () { Random r = new Random (); linha=r.nextInt (Penalti.gol.length); coluna=r.nextInt (Penalti.gol[0].length); Penalti.gol[linha][coluna] = 1; } public Jogador (){ nome = "Hulk chuta"; } } public class Goleiro { int linha ; int coluna; void defende(int linha, int coluna) { this.linha = linha; this.coluna = coluna; Penalti.gol[linha][coluna] = 2; } void defende () { Random r = new Random (); linha=r.nextInt (Penalti.gol.length); coluna=r.nextInt (Penalti.gol[0].length); Penalti.gol[linha][coluna] = 2; for (int u = Penalti.gol.length-1 ; u >= 0; u--){ Penalti.gol[u][coluna] = 2; } } }
codigo 04.05.2017 - turma 3
//******************************************************************* // Dear CompileJava users, // // CompileJava has been operating since 2013 completely free. If you // find this site useful, or would otherwise like to contribute, then // please consider a donation (link in 'More Info' tab) to support // development of the new CompileJava website (stay tuned!). // // Most sincerely, Z. //******************************************************************* import java.lang.Math; // headers MUST be above the first class // one class needs to have a main() method public class HelloWorld { // arguments are passed using the text field below this editor public static void main(String[] args) { OtherClass myObject = new OtherClass("Hello World!"); System.out.print(myObject); /**/ Classe c = new Classe(); System.out.println (c.acesso()[2].toString()); } } public class Classe { private OtherClass o = new OtherClass ("Classe"); OtherClass[] acesso () { OtherClass[] array; array = new OtherClass[10]; array[2]= new OtherClass (); return array; } } // you can add other public classes to this editor in any order public class OtherClass { private String message; private boolean answer = false; public OtherClass () { super(); } public OtherClass(String input) { message = "Why, " + input + " Isn't this something?"; } public String toString() { return message; } }
codigo 04.05.2017 turma 2
//******************************************************************* // Dear CompileJava users, // // CompileJava has been operating since 2013 completely free. If you // find this site useful, or would otherwise like to contribute, then // please consider a donation (link in 'More Info' tab) to support // development of the new CompileJava website (stay tuned!). // // Most sincerely, Z. //******************************************************************* import java.lang.Math; // headers MUST be above the first class // one class needs to have a main() method public class HelloWorld { // arguments are passed using the text field below this editor public static void main(String[] args) { OtherClass myObject = new OtherClass("Hello World!"); System.out.print(myObject); System.out.println (myObject.message); Batata b = new Batata(); System.out.println (b.retornaConteudo().message); System.out.println (b.retornaS()); MeuObjeto meuObjeto = new MeuObjeto(); } } class MeuObjeto { // atributos // metodos } public class Batata { OtherClass o = new OtherClass ("Batata"); OtherClass retornaConteudo () { return o; } String retornaS () { return o.toString(); } } // you can add other public classes to this editor in any order public class OtherClass { public String message; private boolean answer = false; public OtherClass(String input) { message = "Why, " + input + " Isn't this something?"; //return message; } public String toString() { return message; } }
quinta-feira, 20 de abril de 2017
código 20.04.2017 turma 3
//******************************************************************* // Dear CompileJava users, // // CompileJava has been operating since 2013 completely free. If you // find this site useful, or would otherwise like to contribute, then // please consider a donation (link in 'More Info' tab) to support // development of the new CompileJava website (stay tuned!). // // Most sincerely, Z. //******************************************************************* import java.lang.Math; // headers MUST be above the first class // one class needs to have a main() method public class JogoDaVelha { char [][] tabuleiro; // verificar se ganhou, deu velha,... JogoDaVelha() { tabuleiro = new char[3][3]; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { tabuleiro[i][j]=' '; } } } boolean venceu(){ for(int a = 0; a<3; a++){ if(tabuleiro[a][0] == tabuleiro[a][1] && tabuleiro[a][0] == tabuleiro[a][2]) { if(tabuleiro[a][0] != ' '){ System.out.println("Sorte(?)"); return true; } } } return false; } void imprime () { for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { System.out.print (tabuleiro[i][j]); if (j<2) System.out.print ("|"); } if (i<2) System.out.println ("\n------"); } System.out.println ("\n"); } void colocaPeca (char figura, int i, int j) { if(tabuleiro[i][j] == ' '){ tabuleiro[i][j]= figura; } else{ System.out.println("Já foi fera!"); } } // arguments are passed using the text field below this editor public static void main(String[] args) { System.out.println ("xxx"); JogoDaVelha jogo; jogo = new JogoDaVelha(); jogo.imprime(); jogo.colocaPeca ('x', 0,0); jogo.colocaPeca('x',0,1); jogo.colocaPeca('x', 0,2); jogo.venceu(); jogo.imprime(); } }
sábado, 8 de abril de 2017
Código 2 turma 2 07.04.2017 - Ordenação por seleção
01 import java.lang.Math; // headers MUST be above the first class
|
| Java2html |
Código 1 turma 2 - 07.04.2017: Encontrar o menor valor contido em um array
01 import java.lang.Math; // headers MUST be above the first class
|
| Java2html |
quinta-feira, 6 de abril de 2017
código turma 3 06.04.2017
import java.lang.Math; // headers MUST be above the first class
// one class needs to have a main() method
public class HelloWorld
{
// arguments are passed using the text field below this editor
public static void main(String[] args)
{
int i=6;
int[] nome = {-1, 57, -9, 1,12,7, 4, 2024, 68};
for (int contador1 = 0; contador1 < nome.length-1; contador1++){
int menorIndice=contador1;
int menorValor=nome[menorIndice];
for (int posicao = contador1 + 1; posicao < nome.length; posicao++){
//System.out.println (nome[posicao]);
if (menorValor>nome[posicao]) {
// achou um ainda menor
menorIndice=posicao;
menorValor=nome[menorIndice];
}
} //posição
nome[menorIndice] = nome[contador1];
nome[contador1] = menorValor;
System.out.println ("começo do array");
for (int posicao = 0; posicao < nome.length; posicao++){
System.out.println (nome[posicao]);
} // imprime
} //contador1
} //main
} //class
// one class needs to have a main() method
public class HelloWorld
{
// arguments are passed using the text field below this editor
public static void main(String[] args)
{
int i=6;
int[] nome = {-1, 57, -9, 1,12,7, 4, 2024, 68};
for (int contador1 = 0; contador1 < nome.length-1; contador1++){
int menorIndice=contador1;
int menorValor=nome[menorIndice];
for (int posicao = contador1 + 1; posicao < nome.length; posicao++){
//System.out.println (nome[posicao]);
if (menorValor>nome[posicao]) {
// achou um ainda menor
menorIndice=posicao;
menorValor=nome[menorIndice];
}
} //posição
nome[menorIndice] = nome[contador1];
nome[contador1] = menorValor;
System.out.println ("começo do array");
for (int posicao = 0; posicao < nome.length; posicao++){
System.out.println (nome[posicao]);
} // imprime
} //contador1
} //main
} //class
Código turma 3 06.04.2017
import java.lang.Math; // headers MUST be above the first class // one class needs to have a main() method public class HelloWorld { static int chamaInteiro (int i, int[] array){ i=12; array[0] = 17; System.out.println(array[0]); return i; } // arguments are passed using the text field below this editor public static void main(String[] args) { int i=6; int [] array = new int[47]; int[] nome = {-1, -5, -9, 1,3,5, 13, 17, 19}; int menorIndice=0; int menorValor=nome[menorIndice]; for (int posicao = 1; posicao < nome.length; posicao++){ System.out.println (nome[posicao]); if (menorValor>nome[posicao]) { // achou um ainda menor menorIndice=posicao; menorValor=nome[menorIndice]; } } System.out.println (nome); System.out.println ("["+menorIndice+"]=" +menorValor); System.out.println(HelloWorld.chamaInteiro(i,nome)); System.out.println (i); System.out.println(nome[0]); } }
Código 3 turma 2 06.04.2017
import java.lang.Math; // headers MUST be above the first class // one class needs to have a main() method public class HelloWorld { static String[] ret (String[] arr, int x) { int i=5; System.out.println ("x="+x); x=33; System.out.println ("xlinha="+x); System.out.println (arr[0]); arr[2]="ffff"; System.out.println (arr[2]); return arr; } // arguments are passed using the text field below this editor public static void main(String[] args) { int x=314159; System.out.println (args[2]); System.out.println("hello "+ret(args, x)); //System.out.println (args[0]); System.out.println (args[2]); System.out.println ("x="+x); } }
Código 2 turma 2 06.04.2017
import java.lang.Math; // headers MUST be above the first class // one class needs to have a main() method public class HelloWorld { static String[] ret (String[] arr) { int i=5; System.out.println (arr[0]); arr[2]="ffff"; System.out.println (arr[2]); return arr; } // arguments are passed using the text field below this editor public static void main(String[] args) { System.out.println("hello "+ret(args)); //System.out.println (args[0]); //System.out.println (args[1]); } }
código 1 - turma 2 - 06.04.2017
import java.lang.Math; // headers MUST be above the first class // one class needs to have a main() method public class HelloWorld { static String ret (String[] arr) { int i=5; System.out.println (arr[0]); return arr[0]; } // arguments are passed using the text field below this editor public static void main(String[] args) { System.out.println("hello "+ret(args)); //System.out.println (args[0]); //System.out.println (args[1]); } }
quarta-feira, 5 de abril de 2017
Mostrar imagem em Java
Pelo link abaixo faz-se download do código em Java que abre uma janela e mostra (parte de) uma imagem.
https://drive.google.com/open?id=0B2aucTjhMlIVb3J6Nnd5SUVnRU0
https://drive.google.com/open?id=0B2aucTjhMlIVb3J6Nnd5SUVnRU0
quinta-feira, 30 de março de 2017
código turma 3 30.03.2017
import java.lang.Math; // headers MUST be above the first class // one class needs to have a main() method public class HelloWorld { // arguments are passed using the text field below this editor public static void main(String[] args) { int cont = 0; if (args.length>0) System.out.println (args[0]+" "+args[1] + " " + args[2]); int lim = Integer.parseInt(args[2]); while (cont <= lim){ System.out.println(binario(cont)); cont++; } } public static int binario (int decimal) { int binario = 0; int resto = 0; int pot = 1; while (decimal > 0) { resto = decimal%2; decimal = decimal/2; //binario = resto + binario; binario = resto * pot + binario; pot = pot * 10; } return binario; } }
Aula-30.03 turma 3
import java.lang.Math; // headers MUST be above the first class // one class needs to have a main() method public class HelloWorld { // arguments are passed using the text field below this editor public static void main(String[] args) { int cont = 1; while (cont <= 50){ int binario = 0; int resto = 0; int pot = 1; int decimal = cont; while (decimal > 0) { resto = decimal%2; decimal = decimal/2; //binario = resto + binario; binario = resto * pot + binario; pot = pot * 10; } cont++; System.out.println(binario); } } }
Ciódigo da aula de 30.03.2017 turma 2
public class HelloWorld { public static void main(String[] args) { int decimal=64; String binario=""; System.out.println("Iniciando Loop While"); while((decimal)>0){ binario = decimal%2 + binario; decimal = decimal/2; System.out.println(decimal); } System.out.println(binario); } }
sábado, 25 de março de 2017
Leitura de teclado
Na aula foi perguntado como ler do teclado. Abaixo está o código completo de um programa que aguarda que algo seja digitado e repete o que foi escrito. Bom divertimento!
import java.util.Scanner; public class Eco { public static void main(String[] args) { String algo; Scanner sc=new Scanner (System.in); // instancia um objeto scanner que le de // System.in (que representa o teclado) System.out.println ("Por favor digite algo..."); algo=sc.next(); // le string do teclado System.out.println ("Voce digitou: " + algo); } }
Assinar:
Postagens (Atom)