-
-
Save folivetti/55fedfc1dfe46d7c99ff25beba7eb209 to your computer and use it in GitHub Desktop.
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
class SimuladoProva2 { | |
public static int [] criaVetor(int n) { | |
int [] v = new int [n]; | |
for (int i=0; i<n; i++) { | |
v[i] = i+1; | |
} | |
for (int i=0; i<n; i++) { | |
v[i] = v[(int)Math.sqrt(i)]*2; | |
} | |
return v; | |
} | |
public static int [][] Bagunca(int [][] A) { | |
int m = A.length; | |
int n = A[0].length; | |
int [][] B = new int [m][n]; | |
for (int i=0;i<m;i++) { | |
for (int j=0;j<n;j++) { | |
if (i==j && j==n-1-i) { | |
B[i][j] = A[i][j]; | |
} else if (i==j) { | |
B[i][j] = 2*A[i][j]; | |
} else if (j==n-1-i) { | |
B[i][j] = A[i][j]/2; | |
} else { | |
B[i][j] = 2*A[i][j] + 1; | |
} | |
} | |
} | |
return B; | |
} | |
public static int Conta0(String s) { | |
int conta = 0; | |
for (int i=0;i<s.length();i++) { | |
if (s.charAt(i) == '0') conta++; | |
} | |
return conta; | |
} | |
public static void main(String[] args) { | |
/* 1o. exercicio */ | |
int [] v = criaVetor(10); | |
for (int i=0;i<10;i++) { | |
System.out.print(v[i]+" "); | |
} | |
System.out.println(); | |
/* 2o. exercicio */ | |
int [][] A = { {1,2,3}, {4,5,6}, {7,8,9} }; | |
int [][] B = Bagunca(A); | |
for (int i=0;i<3;i++) { | |
for (int j=0;j<3;j++) { | |
System.out.print(B[i][j]+" "); | |
} | |
System.out.println(); | |
} | |
/* 3o. exercicio */ | |
System.out.println(Conta0("quantos 0 vc vai encontrar na string 0?")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment