ACM (TJU) : 2803



package volume_XIX;

import java.util.Scanner;

public class Id_2803 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Scanner input = new Scanner (System.in);
		
		int testCase = input.nextInt();
		
		while ( testCase != 0 ) {
			double a = input.nextDouble();
			double b = input.nextDouble();
			double c = input.nextDouble();
			
			double sq = b * b - 4 * a * c;
			if ( sq < 0 )
				System.out.println ("No solution!");
			
			else {
				double sq1 = -b + Math.sqrt(sq);
				sq1 /= (2 * a);
				
				double sq2 = -b - Math.sqrt(sq);
				sq2 /= (2 * a);
				
				if ( sq1 == sq2 )
					System.out.printf ("%.3f\n", sq1);
				else if ( sq1 > sq2 )
					System.out.printf ("%.3f %.3f\n", sq2, sq1 );
				else
					System.out.printf ("%.3f %.3f\n", sq1, sq2 );
			}
			testCase--;
		}
	}
}


ACM (TJU) : 3251


package volume_XXIII;

import java.util.Scanner;

public class Id_3251 {

/**
* @param args
*/
public static void main(String[] args) {

Scanner input = new Scanner (System.in);

int d = input.nextInt();
int m = input.nextInt();

int days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int week = 6;

outer:
for ( int i = 1; i <= 12; i++ ) { for ( int j = 1; j <= days [i - 1]; j++ ) { if ( i == m && j == d ) break outer; if ( week % 7 == 0 ) week = 0; week++; } } switch (week) { case 1: System.out.println ("Saturday"); break; case 2: System.out.println ("Sunday"); break; case 3: System.out.println ("Monday"); break; case 4: System.out.println ("Tuesday"); break; case 5: System.out.println ("Wednesday"); break; case 6: System.out.println ("Thursday"); break; case 7: System.out.println ("Friday"); break; } } } [/sourcecode]

ACM (UVa) : 10664



package volume_CVI;

import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Id_10664 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Scanner input = new Scanner (System.in);   
		
		String s;
		String temp;
		int m = input.nextInt();
		s = input.nextLine();
		
		while ( m != 0 ) {
			
			int array [] = new int [250];
			int i = 0 ;
			
			s = input.nextLine();
			StringTokenizer stok = new StringTokenizer (s);
			
			while ( stok.hasMoreElements()) {
				temp = stok.nextToken();
				array [i++] = Integer.parseInt(temp);
			}
			
			Arrays.sort(array);
			int hand1 = 0;
			int hand2 = 0;
			
			int j = 0;
			
			while ( j < i ) {
				
				if ( hand1 >= hand2 )
					hand2 += array [array.length - j - 1];
				
				else
					hand1 += array [array.length - j - 1];
				j++;
			}
		
			if ( hand1 - hand2 == 0 )
				System.out.println ( "YES" );
			else
				System.out.println ( "NO" );
			m--;
		}
	}
}


Draw Panel


/*
* Class DrawPanel.java
* Author: Tausiq
* B.Sc in CTE (Studying)
* United International University
*/

import java.awt.Graphics;
import javax.swing.JPanel;

public class DrawPanel extends JPanel {

public void paintComponent ( Graphics g ) {

super.paintComponent(g);

int width = getWidth ();
int height = getHeight ();
int temp_width = 0;
int temp_height = height;

while ( temp_width < width ) { g.drawLine(0, 0, temp_width, temp_height); temp_width += 15; temp_height -= 15; } temp_width = 0; temp_height = 0; while ( temp_width < width ) { g.drawLine(0, height, temp_width, temp_height); temp_width += 15; temp_height += 15; } temp_width = 0; temp_height = 0; while ( temp_width < width ) { g.drawLine(width, 0, temp_width, temp_height); temp_width += 15; temp_height += 15; } temp_width = 0; temp_height = height; while ( temp_width < width ) { g.drawLine(width, height, temp_width, temp_height); temp_width += 15; temp_height -= 15; } } } [/sourcecode] [sourcecode language='java'] /* * Class DrawPanelTest.java (executable) * Author: Tausiq * B.Sc in CTE (Studying) * United International University */ import javax.swing.JFrame; public class DrawPanelTest { public static void main(String[] args) { DrawPanel panel = new DrawPanel (); JFrame a = new JFrame (); a.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ); a.add(panel); a.setSize(250, 250); a.setVisible(true); } } [/sourcecode]

Setting path variable (JDK)


  • Right click on ‘My Computer’ > select Properties. A dialog box will appear named ‘System Properties’

    System_Properties

    System_Properties

  • select (tab) Advanced > Environment Variables

    Advance (tab)

    Advance (tab)

  • in the ‘System variables’, select ‘path’ and click on ‘Edit’

    Environment_variables

    Environment_variables

  • Place the cursor at the beginning of ‘Variable value’ and insert the path of ur JDK (bin) folder. By default it should be,
    C:\Program Files\Java\jdk1.6.0_13\bin; (semicolon at the end)
    click ok.

    Edit_System_variable

    Edit_System_variable

    that’s all !!

Running a Java File using Command Prompt


  • To execute a .java file u have to have installed JDK.
    Make sure, u have JDK (Java Development Kit) installed in ur pc
    if u don’t have it, then u can download the latest version of JDK from (http://java.sun.com/javase/downloads/index.jsp)
    download and install it.

  • create a .java file using a text editor ( like Notepad, Wordpad )

    Test.java

    Test.java

  • give a name (Example : Test) with .java extension [Test.java]
    remember the file type must have the extension .java (not .txt)

  • Copy this file and paste it in ‘bin’ folder.
    U will get it where u installed ur JDK.
    By default it should be, C:\Program Files\Java\jdk1.6.0_13\bin

  • Running Command Prompt :
    1. Start menu > All Programs > Accessories > Command Prompt. Or,
    2. Start menu > Run… > (type) cmd > click ok.

  • In Command prompt :
    type the key word “cd” .. which means change directory (cd)
    give a space and type the full path of ur JDK (bin) folder
    By default it should be, C:\Program Files\Java\jdk1.6.0_13\bin
    press Enter

    Command Prompt

    Command Prompt

  • Now type : javac Test.java
    press Enter
    a file named (Test.class) will be created automatically after this command, in bin directory. Check it.

    Command Prompt_2

    Command Prompt_2

  • Now type: java Test
    press Enter

    Command Prompt_3

    Command Prompt_3

  • A dialog box will appear
    write a name input box and click ok.

    Input_Dialog

    Input_Dialog

  • A message will be showed, displaying the name
    click ok.

    Message_box

    Message_box

  • Now go back to the command prompt and type ‘exit’
    press Enter.

    Command Prompt_4

    Command Prompt_4

  • Congratulation !!!
    u have successfully executed a Java file using command prompt.