Difference between revisions of "CSC231 MultBy3.java Program"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- <source lang="java"> // MultBy3.java // D. Thiebaut // A simple program to illustrates what happens when an overflow occurs // in an int variable. // // To compile ...")
 
Line 16: Line 16:
  
 
     public static void main( String[] args ) {
 
     public static void main( String[] args ) {
long a = 2;
+
int a = 2;
 
for ( int i=0; i<70; i++ ) {
 
for ( int i=0; i<70; i++ ) {
  

Revision as of 08:09, 3 October 2012

--D. Thiebaut 08:08, 3 October 2012 (EDT)


// MultBy3.java
// D. Thiebaut
// A simple program to illustrates what happens when an overflow occurs
// in an int variable.
//
// To compile and run:
//  javac MultBy3.java
//  java MultBy3
//
public class MultBy3 {

    public static void main( String[] args ) {
	int a = 2;
	for ( int i=0; i<70; i++ ) {

	    System.out.println( a );
	    //System.out.println( String.format( "%20d %16s %64s", a , Long.toHexString(a), Long.toBinaryString( a ) ) );
	    //System.out.println( String.format( "%12d %8s %32s", a , Integer.toHexString(a), Integer.toBinaryString( a ) ) );

	    a *= 3;

	}
    }
}