User:Binari: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
No edit summary
Line 37: Line 37:
i=i/2;
i=i/2;
}
}
}
}
</lang>

==Loops/Nested==
<lang java>
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
int i,j;
int[][] ar=new int[20][20];
Random rast=new Random();
for (i=0; i<20; i++) {
for (j=0; j<20; j++) {
ar[i][j]=rast.nextInt(20)+1;
}
}
System.out.println("R C");
for (i=0; i<20; i++) {
for (j=0; j<20; j++) {
if (ar[i][j]==20) {
System.out.println(i+" "+j);
break;
}
}
}
// your code goes here
}
}
}
}

Revision as of 07:38, 1 August 2015

Hello World/Graphical

<lang java> import javax.swing.*;

class helloGUI { private helloGUI() { JFrame.setDefaultLookAndFeelDecorated(true); JFrame penc=new JFrame("Elveda"); penc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel yaz=new JLabel("Goodbye, World!"); penc.getContentPane().add(yaz); penc.pack(); penc.setVisible(true); } public static void main(String[] args) { new helloGUI(); } } </lang>

Hello world/Newline omission

<lang java> class noNewline { public static void main(String[] args) { System.out.print("Goodbye, World!"); } } </lang>

Loops/While

<lang java> class whileLoop { public static void main(String[] args) { int i=1024; while (i>0) { System.out.println(i); i=i/2; } } } </lang>

Loops/Nested

<lang java> /* package whatever; // don't place package name! */

import java.util.*; import java.lang.*; import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { int i,j; int[][] ar=new int[20][20]; Random rast=new Random(); for (i=0; i<20; i++) { for (j=0; j<20; j++) { ar[i][j]=rast.nextInt(20)+1; } } System.out.println("R C"); for (i=0; i<20; i++) { for (j=0; j<20; j++) { if (ar[i][j]==20) { System.out.println(i+" "+j); break; } } } // your code goes here } } </lang>