Template by:
Free Blog Templates

Monday, August 3, 2009

Getting Input - Java



A- Getting Input from the Console - Scanner

1. Write a coding below and see the output:

(Text book: page 79- Listing 2.9)

import java.util.Scanner;

public class TestScanner {

public static void main(String args[]) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter an integer:");

int intValue=scanner.nextInt();

System.out.println("You entered the integer:"+ intValue);

System.out.print("Enter a double value:");

double doubleValue=scanner.nextDouble();

System.out.println("You entered the double value:"+ doubleValue);

System.out.print("Enter a string without space:");

String string=scanner.next();

System.out.println("You entered the string:" +string);

}

}

Output:


B- Displaying Text in a Message Dialog Box

  1. Write the code as below:

/* This application program display Welcome to Java! In a message dialog box.*/

import javax.swing.JOptionPane;

public class WelcomeInMessageDialogBox {

public static void main(String [] args) {

//Display Welcome to Java! In a message dialog box

JOptionPane.showMessageDialog (null, “Welcome to Java!”, “Display Message”, JOptionPane.INFORMATION_MESSAGE);

}

}

Output



C- Getting Input from the Console - MyInput


public class task1a

{

public static void main (String [] args)

{

System.out.print("Enter measure in inch:");

double inche = MyInput.readDouble();

double cm = 2.54 *inche;

double feet = cm * 12;

System.out.println("Converting from " + inche + " Inch to feet is " + feet);

}

}


Output


Wednesday, July 29, 2009

Pengumuman!!!!!!

Kepada Semua Student Software Engineering!!!!!
Kelas Dr Pouzi pada minggu hadapan tiada..

Monday, July 27, 2009

Pelajar Software Engineering dan Fizik ke Pulau BIDONG!!!




Pada tanggal 24 Julai 2009 pelajar dari Jurusan Software Engineering dan Fizik dan Instrumentasi telah bertolak Ke Pulau Bidong untuk menyertai Servival laut dan Jejak Warisan.
Seramai 160 orang perserta telah menjejakan kaki disana pada pukul 10 pagi dengan penuh ceria.
mari kita lihat gelagat mereka.Terasa Mcm Titanic
Tarian Cina Yang x mcm cina

Ni pose pe plk nk
Lelaki pingiran lautan