Solutions Premiers Pas



Similar documents
Licence Informatique Année Exceptions

TP N 10 : Gestion des fichiers Langage JAVA

public static void main(string[] args) { System.out.println("hello, world"); } }

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Langages Orientés Objet Java

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

Annexe - OAuth Introduction. Xavier de Rochefort xderoche@labri.fr - labri.fr/~xderoche 15 mai 2014

Sample CSE8A midterm Multiple Choice (circle one)

13 File Output and Input

TP1 : Correction. Rappels : Stream, Thread et Socket TCP

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Chapter 2 Introduction to Java programming

Introduction to Java

WRITING DATA TO A BINARY FILE

Basic Java Syntax. Program Structure

COSC Introduction to Computer Science I Section A, Summer Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

Lesson: All About Sockets

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Mail User Agent Project

Apéndice C: Código Fuente del Programa DBConnection.java

J a v a Quiz (Unit 3, Test 0 Practice)

CS 121 Intro to Programming:Java - Lecture 11 Announcements

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1

Introduction to Object-Oriented Programming

Consuming a Web Service(SOAP and RESTful) in Java. Cheat Sheet For Consuming Services in Java

Continuous Integration Part 2

Object-Oriented Programming in Java

Database Access from a Programming Language: Database Access from a Programming Language

Database Access from a Programming Language:

Part I. Multiple Choice Questions (2 points each):

POB-JAVA Documentation

Brazil + JDBC Juin 2001, douin@cnam.fr

CSC 551: Web Programming. Fall 2001

ExempleRMI.java. // Fichier de defintion des droits et proprietes // System.setProperty("java.security.policy","../server.java.

Software Development with UML and Java 2 SDJ I2, Spring 2010

Collections.sort(population); // Método de ordenamiento

CS 106 Introduction to Computer Science I

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Homework/Program #5 Solutions

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

INPUT AND OUTPUT STREAMS

Lecture J - Exceptions

Creating a Simple, Multithreaded Chat System with Java

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Chapter 5. Recursion. Data Structures and Algorithms in Java

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

Example of a Java program

niveau : 1 ere année spécialité : mécatronique & froid et climatisation AU : Programmation C Travaux pratiques

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Socket-based Network Communication in J2SE and J2ME

Course Intro Instructor Intro Java Intro, Continued

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

AP Computer Science Java Subset

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 2 November 21, 2011 SOLUTIONS.

Files and input/output streams

Remote Method Invocation

AP Computer Science Static Methods, Strings, User Input

core 2 Basic Java Syntax

Java Programming Fundamentals

TP JSP : déployer chaque TP sous forme d'archive war

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Advanced Network Programming Lab using Java. Angelos Stavrou

The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

Iteration CHAPTER 6. Topic Summary

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Topic 11 Scanner object, conditional execution

Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion

An Overview of Java. overview-1

Advanced OOP Concepts in Java

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

Building Java Programs

Network Programming using sockets

Network Communication

Chapter 5 Aspect Oriented Programming

Event-Driven Programming

JAVA - FILES AND I/O

OBJECT ORIENTED PROGRAMMING LANGUAGE

File I/O - Chapter 10. Many Stream Classes. Text Files vs Binary Files

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.

Evaluation. Copy. Evaluation Copy. Chapter 7: Using JDBC with Spring. 1) A Simpler Approach ) The JdbcTemplate. Class...

Introduction. GEAL Bibliothèque Java pour écrire des algorithmes évolutionnaires. Objectifs. Simplicité Evolution et coévolution Parallélisme

Quick Introduction to Java

Liferay, Alfresco, SSO and LDAP Full Integration

Introduction to Programming

Using Files as Input/Output in Java 5.0 Applications

Data Communication & Networks G

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Basics of Java Programming Input and the Scanner class

CmpSci 187: Programming with Data Structures Spring 2015

The following program is aiming to extract from a simple text file an analysis of the content such as:

Unit 6. Loop statements

Using Two-Dimensional Arrays

What is an I/O Stream?

! "# $%&'( ) * ).) "%&' 1* ( %&' ! "%&'2 (! ""$ 1! ""3($

Transcription:

Solutions Premiers Pas Solution 1: public class HelloWorld { System.out.println("Hello World!"); Solution 2 : public class HelloWorld { System.out.println(args[0]); Solution 3 : public class HelloWorldWithMethod{ public void Hello(){ System.out.print( You re Welcome! ); HelloWorldWithMethod s=new HelloWorldWithMethod(); s.hello(); Solution 4 : public class HelloWorldWithAttribut { String machaine; public void Hello(){ System.out.print(maChaine); HelloWorldWithAttribut s=new HelloWorldWithAttribut (); s.machaine= salut ; s.hello();

Solutions Généralités Solution 1 : class Somme{ public static void main(string[] arg){ int i, somme = 0; for (i = 1; i <= 100; i++){ somme += i; System.out.println("Voila la somme des 100 " + " premiers entiers : " + somme); Solution 2 public class Segment{ int extr1, extr2; Segment(int e1, int e2){ extr1 = e1; extr2 = e2; void ordonne(){ if (extr1 > extr2){ int tampon; tampon = extr1; extr1 = extr2; extr2 =tampon; int longueur(){ ordonne(); return extr2 - extr1; boolean appartient(int x){ return (x - extr1) * (x - extr2) <= 0; ordonne(); return "segment [" + extr1 + ", " + extr2 + "]"; public class EssaiSegment{ Segment s = new Segment(Integer.parseInt(argv[0]), Integer.parseInt(argv[1])); int point; System.out.println("Longueur du " + s + " : " + s.longueur()); point = Integer.parseInt(argv[2]); if (s.appartient(point)) System.out.println(point + " appartient au " + s); System.out.println(point + " n'appartient pas au " + s);

Solution 4 public class Factorielle{ int n, factorielle = 1 ; n = Integer.parseInt(argv[0]); for (int i = 2; i <= n; i++) factorielle *= i; System.out.println("Voila la factorielle de " + n + " : " + factorielle); Solution 5 Première méthode public class Palindrome{ static String inverse(string s){ int longueur = s.length(); char [] envers = new char[longueur]; int i; for (i = 0; i < longueur; i++) envers[i] = s.charat(longueur - i - 1); return new String(envers); public static void main(string[] arg) { String chaine = arg[0]; String autre = inverse(chaine); System.out.println("L'inverse de " + chaine + " est " + autre); if (autre.equals(chaine)) System.out.println(chaine + " est un palindrome"); System.out.println(chaine + " n'est pas un palindrome"); Deuxième méthode import java.io.*; public class Palindrome2{ static String inverse(string s){ int longueur = s.length(); char [] envers = new char[longueur]; int i; for (i = 0; i < longueur; i++) envers[i] = s.charat(longueur - i - 1); return new String(envers); public static void main(string[] arg) throws IOException{ BufferedReader entree = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Indiquez la chaîne de caractères"); String chaine = entree.readline(); String autre = inverse(chaine); System.out.println("L'inverse de \"" + chaine + "\" est \"" + autre + "\""); if (autre.equals(chaine)) System.out.println("\"" + chaine + "\" est un palindrome"); System.out.println("\"" + chaine + "\" n'est pas un palindrome");

Solution 6 public class Vecteur{ int abs, ord; Vecteur(int _abs, int _ord){ abs = _abs; ord = _ord; double longueur(){ return Math.sqrt(abs * abs + ord * ord); void addition(vecteur v){ abs = v.abs + abs; ord = v.ord + ord; static Vecteur addition(vecteur v1, Vecteur v2){ return new Vecteur(v1.abs + v2.abs, v1.ord + v2.ord); boolean pluspetitque(vecteur v){ return longueur() < v.longueur(); return "vecteur (" + abs + ", " + ord + ")"; public class EssaiVecteur{ Vecteur v1 = new Vecteur(Integer.parseInt(argv[0]), Integer.parseInt(argv[1])); System.out.println("v1 : " + v1); System.out.println("Longueur de " + v1 + " : " + v1.longueur()); Vecteur v2 = new Vecteur(Integer.parseInt(argv[2]), Integer.parseInt(argv[3])); System.out.println("v2 : " + v2); if (v1.pluspetitque(v2)) System.out.println("Le " + v1 + " est plus petit que le " + v2); System.out.println("Le " + v1 + " est au moins aussi grand que " + "le " + v2); v1.addition(v2); System.out.println("v1 après addition de v2 : " + v1); Vecteur v3 = Vecteur.addition(v1, v2); System.out.println("v3 = v1 + v2 : " + v3); Solution 7 : class ExceptionPileVide extends Exception{ return "la pile est vide"; Méthode1 public class Pile1{ private int taille = 3; private int increment = 2; private int[] tableau = new int[taille]; private int hauteur; // nombre d'entiers rangés

void empiler(int n){ if (hauteur == taille){ taille = taille + increment; int[] tableaubis = new int[taille]; for (int i = 0; i < hauteur; i++) tableaubis[i] = tableau[i]; tableau = tableaubis; tableau[hauteur] = n; hauteur++; int depiler() throws ExceptionPileVide{ int cle; if (estvide()) throw new ExceptionPileVide(); hauteur--; return tableau[hauteur]; boolean estvide(){ return hauteur == 0; Méthode 2 public class Maillon { int donnee; Maillon suivant; Maillon(int donnee, Maillon suivant) { this.donnee = donnee; this.suivant = suivant; public class Pile2{ private Maillon debut; void empiler(int n) { debut = new Maillon(n, debut); int depiler() throws ExceptionPileVide { int cle; if (estvide()) throw new ExceptionPileVide(); cle = debut.donnee; debut = debut.suivant; return cle; boolean estvide() { return debut == null;