Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // QCM: a, c, a, ab, a, b, a, a, a, b', a, c, a, a'
- // ex2
- public class Complex {
- // Variables d'instance
- private double real, imag;
- // Constructeur
- public Complex (double r, double i) {
- this.real = r;
- this.imag = i;
- }
- // Partie réelle
- public double getRealPart() {
- return real;
- }
- // Partie imaginaire
- public double getImagPart(){
- return imag;
- }
- // Additionner deux complexes
- public Complex add (Complex c) {
- return new Complex(this.real + c.getRealPart(), this.imag + c.getImagPart());
- }
- // Soustraire deux complexes
- public Complex subtract (Complex c) {
- return new Complex(this.real - c.getRealPart(), this.imag - c.getImagPart());
- }
- // Calculer le conjugué
- public Complex conjugate() {
- return new Complex(this.real, -this.imag);
- }
- public static void main(String args[]) {
- Complex a = new Complex(2.5, 1);
- Complex b = new Complex(1, 1.5);
- Complex c = a.add(b);
- double r = c.getRealPart();
- double i = c.getImagPart();
- System.out.println(r+" + "+i+"i");
- Complex d = c.conjugate().subtract(b);
- System.out.println(d.getRealPart()+" + "+d.getImagPart()+"i");
- }
- }
- // ex3
- public class Pawn extends ChessPiece {
- public Pawn(int color, int row, int col) {
- super(color, row, col);
- }
- @Override
- public int[][] getMoves() {
- int[][] T = new int[1][2];
- T[0][1] = col; // wont change as long as we ignore other pieces
- if(super.color == BLACK && row < 7)
- T[0][0] = row + 1;
- else if(super.color == WHITE && row > 0)
- T[0][0] = row - 1;
- else
- T[0][0] = row;
- return T;
- }
- public static void main(String args[]) {
- Pawn pion = new Pawn(BLACK, 4, 2);
- int[][] moves = pion.getMoves();
- System.out.print(moves [0][0] + " " + moves[0][1]);
- }
- }
- // ex4
- import java.util.Scanner;
- public class Voyelles{
- public static void main (String args[]){
- Scanner sc = new Scanner(System.in);
- String str = sc.nextLine();
- char[] T = {'a', 'e', 'i', 'o', 'u', 'y'};
- int[] cpt = new int[6];
- for ( int i=0 ; i<str.length() ; i++ )
- {
- for( int j=0 ; j<T.length ; j++)
- if(str.toLowerCase().charAt(i) == T[j])
- cpt[j]++;
- }
- for(int i=0; i<T.length ; i++)
- System.out.println(cpt[i] + " fois la lettre " + T[i]);
- }
- }
- // ex5
- JFrame -> Frame -> Window -> Container -> Component -> Object
Add Comment
Please, Sign In to add comment