Skip to content
Snippets Groups Projects
Commit 387eb374 authored by Kevin Bonga's avatar Kevin Bonga
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 532 additions and 0 deletions
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/serie1.iml" filepath="$PROJECT_DIR$/serie1.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
import static java.lang.Math.pow;
import static java.lang.Math.sqrt;
public class Main {
//Exo 1.1
public static void whileWithDoWhile(int i){
do {
System.out.println(i);
i++;
}
while(i<5);
}
public static void whileWithWhile(int i){
System.out.println(i);
while(i<5){
i++;
System.out.println(i);
}
}
//Exo 1.2
//byte b =s; //ne compile pas
//Exo 1.3
/*short s=10;
s=s+s;
s=s*2;*/
//Exo 1.3 promotion numérique
/*
1 compile
2 compile pas
3 oui
*/
//Exo 1.4
// short s=10;
// int k = ++s;
// System.out.println(k); // vaut 10
//Exo 1.6
public static void printTriangle(int n){
int i = 1;
while (i<=n){
for (int j = 0; j < i; j++) {
System.out.print('*');
}
System.out.print('\n');
i++;
}
}
//une boucle for en plus
public static void printSapin(int n){
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
//System.out.print('*');
System.out.print('*');
}
System.out.print('\n');
}
}
//Exo 1.8
public static void factorielle(int n){
int factoriel=1;
for (int i = 1; i <= n; i++) {
factoriel*=i;
}
System.out.println(factoriel);
}
public static void computePi(int n){
double nbPi=0;
for (int i = 1; i < n; i++) {
nbPi += 1/pow(i,4);
}
System.out.println(nbPi);
System.out.println(pow(3.14,4)/90);
}
public static void snake(){
}
//Exo 1.11 Vecteurs
public static double []add(double []vec1, double []vec2){
double [] res=new double[Math.max(vec1.length, vec2.length)];
if(vec1.length != vec2.length){
System.out.println("pas possible d'additionner des vecteurs de taille différente");
return res;
}
for(int i=0; i< vec1.length; i++){
res[i]= vec1[i]+vec2[i];
}
return res;
}
public static double []mul(double []vec1, int n){
double [] res =new double[vec1.length];
for (int i = 0; i < vec1.length; i++) {
res[i]= vec1[i] * n;
}
return res;
}
public static double[]sub(double []vec1, double [] vec2){
return add(vec2, mul(vec1, -1));
}
public static int len(double []vec){
return vec.length;
}
public static double norm(double []vec){
double res=0;
for (int i = 0; i < vec.length; i++) {
res += pow(vec[i], 2);
}
return sqrt(res);
}
public static double[] sum(double []...tab){
double [] res = new double[tab[0].length];
for (double[] v : tab) {
res = add(res, v);
}
return res;
}
public static double norms(double []...tab){
double [] res = sum(tab);
return norm(res);
}
public static void printMatrix(int [][] matrix){
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix.length; j++) {
System.out.print(matrix[i][j]);
}
System.out.print("\n");
}
}
// 3 boucles for, une pour les lignes et espaces, pour les étoiles
//test de l’égalité de deux matrices
public static boolean matrix_is_equal(int [][] mat1, int [][] mat2){
return (mat1[0].length*mat1[1].length)==(mat2[0].length*mat2[0].length);
}
public static int [][] matrix_add(int [][] mat1, int [][] mat2){
int [][] mat = new int[mat1.length][mat1.length];
if (matrix_is_equal(mat1,mat2)){
for (int i = 0; i < mat1[0].length; i++) {
for (int j = 0; j < mat1[1].length; j++) {
mat[i][j] = mat1[i][j] + mat2[i][j];
}
}
return mat;
}
mat = new int[0][0];
return mat;
}
public static int countPositive(double [][] tab){
int cpt=0;
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab.length; j++) {
if (tab[i][j]>0)
cpt++;
}
}
return cpt;
}
public static boolean isNumeric(String term){
for (int i = 0; i < term.length(); i++) {
if (Character.isDigit(term.charAt(i))){
if(Character.isLetter(term.charAt(i))){
return false;
}
}
}
return true;
}
public static int[] indexes(String term, char c){
int[]tab = new int[term.length()];
int cpt=0;
for(int i =0; i< term.length();i++) {
if(term.charAt(i)==c){
tab[cpt]=i;
cpt++;
}
}
return tab;
}
public static void main(String[] args) {
//printSapin(4);
//computePi(3);
System.out.println(isNumeric("22"));
//System.out.println(Arrays.toString(indexes("Bonsoir Paris yeaah",'a')));
}
}
\ No newline at end of file
File added
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/serie2.iml" filepath="$PROJECT_DIR$/serie2.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
import java.util.Objects;
public class Account {
private int amount;
private String owner;
private TestAccount state;
public Account(String owner) {
this(owner,0);
}
public Account(String owner, int amount) {
if(amount>=0) {
this.amount = amount;
this.owner = owner;
this.state = TestAccount.VERT;
}else{
throw new RuntimeException("Cant blalbalbal");
}
}
public static Account of(String owner, int amount) {
if (amount < 0) {
throw new RuntimeException("Amount must be positive");
}
return new Account(owner, amount);
}
public int amount(){
return this.amount;
}
public void deposite(int value){
if(amount>0){
this.amount += amount;
if(this.amount>0){
state=TestAccount.VERT;
}else{
throw new RuntimeException("Account can't be added with negative amount");
}
}
this.amount +=value;
}
public void withdraw(int amount) {
if (this.amount - amount > -2000) {
this.amount -= amount;
if (this.amount<0){
this.state = TestAccount.ROUGE;
}
}
else{
throw new RuntimeException("Account must be positive");
}
}
public String getOwner(){
return this.owner;
}
public boolean equals(Object b){
if(this==b){
return true;
}else if(b instanceof Account){
if(owner.equals(((Account)b).owner) && amount == ((Account)b).amount){
return true;
}
else{
return false;
}
}
else{
return false;
}
}
public Account create_account(String owner, int amount){
return new Account(this.owner, 0);
}
public Account create_account2(int value){
if (value <= 0) {
throw new RuntimeException("Account must be positive");
}
this.amount = value;
return null;//new Account();
}
public static void transfer(Account acc1, Account acc2, int amount){
acc1.withdraw(amount);
acc2.deposite(amount);
}
public boolean testAmount(Account acc, int min){
return acc.amount >= min;
}
public static boolean sameAccount(Account acc1, Account acc2){
return Objects.equals(acc1.owner, acc2.owner) && acc1.amount == acc2.amount;
}
}
public class ContainerHelper {
public void transfer(ContainerHelper cont1, ContainerHelper cont2){
}
public static void appendInt(int val, int []tab){
int size = tab.length;
//tab.length +=1;
while (size!=0){
}
}
public static int tabHead(int []tab){
return tab[0];
}
public static int tabTail(int []tab){
return tab[tab.length-1];
}
}
public class Main {
public static void main(String[] args) {
}
}
\ No newline at end of file
public enum TestAccount {
VERT,
ROUGE,
VIP
}
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/exos.iml" filepath="$PROJECT_DIR$/exos.iml" />
</modules>
</component>
</project>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment