Basic Input and Output

J1.java – Java Programming Quick Start

This code includes Java Building Blocks, Primitive Data Types, basic input and output. Remember, the class name should be the file name plus .java extension. Like this code, the title of the class is J1, so the name of the file also must be J1 plus the extension of .java, that’s why you should name it “J1.java”. Java is Case-Sensitive.

You can compile this program without changing anything

.
// include the Scanner class (from java.util package)
import java.util.Scanner;

public class J1 {
public static void main (String args[ ] ) {
// declare variables of type double, float, int, and byte
double d; float f; int i; byte b; String s;
// declare and instantiate a Scanner object
Scanner input = new Scanner(System.in);

// read values using input (Scanner object)
System.out.println(“Enter a byte, int, float, and double”);
b = input.nextByte();
i = input.nextInt();
f = input.nextFloat();
d = input.nextDouble();
s = input.nextLine();

// output values using println( )
System.out.print(“byte = ” + b + ” int = ” + i);
System.out.println(” float = ” + f + ” double = ” + d + “ string = “ + s);

// output values using printf( ). (for version 1.5 and higher)
// the syntax for format specifier is similar to C programming
System.out.printf(“%d %d %.2f %.3f %s\n”, b, i, f, d, s);
}
}

// EOF: J1.java

2 Comments »

  1. BRIAN Said,

    September 8, 2010 @ 1:27 am


    CheapTabletsOnline.com. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices.Best quality drugs. High quality pills. Order pills online

    Buy:Zovirax.Arimidex.Actos.Lumigan.Human Growth Hormone.Zyban.Nexium.Valtrex.Prevacid.Petcam (Metacam) Oral Suspension.Synthroid.Retin-A.100% Pure Okinawan Coral Calcium.Prednisolone.Mega Hoodia.Accutane….

  2. WAYNE Said,

    November 11, 2010 @ 3:31 am


    NEW FASHION store. Original designers collection at low prices!!! 20 % TO 70 % OFF. END OF SEASON SALE!!!

    BUY FASHION. TOP BRANDS: GUCCI, DOLCE&GABBANA, BURBERRY, DIESEL, ICEBERG, ROBERTO CAVALLI, EMPORIO ARMANI, VERSACE…

RSS feed for comments on this post · TrackBack URI

Leave a Comment