99 bottles of beer: Difference between revisions

no edit summary
(added ocaml)
No edit summary
Line 446:
(format t "~a bottles of beer on the wall~%" (- x 1))
(if (> (- x 1) 0)
(bottles (- x 1))))</lisp>
 
and then just call
Line 797:
import javax.swing.JTextArea;
public class Beer extends JFrame implements ActionListener{
private int x;
private JButton take;
private JTextArea text;
public static void main(String[] args){
new Beer();//build and show the GUI
}
}
 
public Beer(){
x= 99;
take= new JButton("Take one down, pass it around");
text= new JTextArea(4,30);//size the area to 4 lines, 30 chars each
text.setText(x + " bottles of beer on the wall\n" + x + " bottles of beer");
take.addActionListener(this);//listen to the button
setLayout(new BorderLayout());//handle placement of components
add(text, BorderLayout.CENTER);//put the text area in the largest section
add(take, BorderLayout.SOUTH);//put the button underneath it
pack();//auto-size the window
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//exit on "X" (I hate System.exit...)
setVisible(true);//show it
}
}
 
public void actionPerformed(ActionEvent arg0){
if(arg0.getSource() == take){//if they clicked the button
--x;
--x;
JOptionPane.showMessageDialog(null, x + " bottles of beer on the wall");//show a popup message
text.setText(x + " bottles of beer on the wall\n" + x + " bottles of beer");//change the text
}
}
if(x == 0){//if it's the end
dispose();//end
}
}
}
}
}</java>
 
Line 866:
} reverse (1..99);
</perl>
 
=={{header|Pop11}}==
<pre>
define bootles(n);
while n > 0 do
printf(n, '%p bottles of beer on the wall\n');
printf(n, '%p bottles of beer\n');
printf('Take one down, pass it around\n');
n - 1 -> n;
printf(n, '%p bottles of beer on the wall\n');
endwhile;
enddefine;
 
bootles(99);
</pre>
 
=={{header|Python}}==
Anonymous user