Skip to content

Instantly share code, notes, and snippets.

@arnaudbos
Last active September 23, 2019 16:54
Show Gist options
  • Save arnaudbos/eb92af3fd4de77d932b4fcdbb258bf00 to your computer and use it in GitHub Desktop.
Save arnaudbos/eb92af3fd4de77d932b4fcdbb258bf00 to your computer and use it in GitHub Desktop.
Quiz Archive
public class Archie {
public static void main(String[] args) {
Pattern p = Pattern.compile(args[0]);
Matcher m = p.matcher(args[1]);
int count = 0;
while (m.find()) count++;
System.out.println(count);
}
}
class Top {
public Top(String s) {
System.out.println("B");
}
}
class Bottom extends Top {
public Bottom(String s) {
System.out.println("D");
}
public static void main(String[] args) {
new Bottom("C");
System.out.println(" ");
}
}
public class ComparaisonNumerique {
public static void main(String[] args) {
int i = 4;
float f = 4.3;
double d = 1.8;
int c = 0;
if (i == f)
c++;
if (((int) (f + d)) == ((int) f + (int) d))
c += 2;
System.out.println(c);
}
}
public class EtBenOui {
static int value;
static boolean a() {
return value++ > 1;
}
static boolean b() {
return value++ > 1;
}
static boolean c() {
return value++ > 1;
}
public static void main(String[] args) {
if (a() & b()) {
c();
}
else{
System.out.println("Bim");
}
System.out.println(value);
}
}
public class Foo
{
public static void main(String[] args)
{
try
{
System.exit(-1);
}
finally
{
System.out.println( "Finally" );
}
}
}
public static void main (String[] args)
{
try
{
System.out.print ("A");
int value = Integer.parseInt ("8A");
System.out.print ("B");
}
catch (NumberFormatException exception)
{
System.out.print ("C");
return;
}
finally
{
System.out.print ("D");
}
System.out.print ("E");
}
class Bar { }
class Test
{
Bar doBar()
{
Bar b = new Bar(); /* Line 6 */
return b; /* Line 7 */
}
public static void main (String args[])
{
Test t = new Test(); /* Line 11 */
Bar newBar = t.doBar(); /* Line 12 */
System.out.println("newBar");
newBar = new Bar(); /* Line 14 */
System.out.println("finishing"); /* Line 15 */
}
}
int x = 5;
double y = 3.5;
if (x > 5 && y > x || x + 3 < y + 1)
System.out.println ("A");
else if (x < y + 1 && x + y <= 12)
System.out.println ("B");
else System.out.println ("C");
public class Leader implements Runnable {
public static void main(String[] args) throws InterruptedException {
Thread t = new Thread(new Leader());
t.start();
System.out.print(" m1");
t.join();
System.out.print(" m2");
}
public void run() {
System.out.print(" r1");
System.out.print(" r2");
}
}
class Mixer {
Mixer m1;
Mixer() {}
Mixer(Mixer m) {m1 = m;}
public static void main(String[] args) {
Mixer m2 = new Mixer();
Mixer m3 = new Mixer(m2); m3.go();
Mixer m4 = m3.m1; m4.go();
Mixer m5 = m2.m1; m5.go();
}
private void go() { System.out.println("hi "); }
}
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
i -= i++ - --i;
System.out.println("Hello world!") ;
}
}
public abstract class AbstractRegister {
private Connection getDatabase(){
// return Connection
}
//Different for User, Admin, SuperBoss
public abstract String getTable();
private String writeQuery(){
return "INSERT INTO "+getTable()+ " BLABLABLA;";
}
private void tweetThatStuff(){/* tweet stuff*/}
public void execute(){
getDatabase().write(writeQuery());
tweetThatStuff();
}
}
public class TopicPattern {
Topic s;
public TopicPattern addComment(Comment comment){
// add a comment to the topic
return this;
}
public TopicPattern addFlag(Comment c, User u, String reason){
//flag the topic with bad comment
return this;
}
}
class StarrableSubjectPattern extends TopicPattern{
public TopicPattern addStar(Star star){
// user says this comment rocks
return this;
}
}
PriorityQueue<String> pq = new PriorityQueue<>();
pq.add("2");
pq.add("4");
System.out.print(pq.peek() + " ");
pq.add("3");
pq.remove("1");
System.out.print(pq.poll() + " ");
if (pq.remove("2")) System.out.println(pq.poll() + " ");
System.out.println(pq.poll() + " " + pq.peek());
public class Quiz2 {
private static class MonRunnable implements Runnable {
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// Pas bien !
}
System.out.println("Bonjour");
}
}
public static void main(String[] args) {
Thread t = new Thread(new MonRunnable());
t.run();
System.out.println("Au revoir");
}
}
String input = "1 2 a 3 45 6";
try (Scanner sc = new Scanner(input)) {
int x = 0;
do {
x = sc.nextInt();
System.out.print(x + " ");
} while (sc.hasNextInt());
}
public class SustainableDev {
public static void main(String[] args) {
int a = 8; int b = 2;
a = a ^ b;
b = a ^ b;
a = a ^ b;
System.out.println("a = " + a + "; b = " + b);
}
}
class A { void m() { System.out.println("outer"); } }
public class TestInners {
public static void main(String[] args) {
new TestInners().go();
}
void go() {
new A().m();
class A { void m() { System.out.println("inner"); } }
}
class A { void m() { System.out.println("middle"); } }
}
class Business{}
class Hotel extends Business {}
class Inn extends Hotel {}
class Travel {
List<Hotel> go(){
//insert code here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment