IntWrapper - " is" Integer.toBinaryString(intVal"" System.out.println"The octal representation of" intVal" is"

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//****************************************************************** // IntWrapper.java // // Read in integers and manipulate them using methods in the // Integer wrapper class. //****************************************************************** import java.util.Scanner; public class IntWrapper { //-------------------------------------------------------- // Reads in integer and prints binary, octal, and hex // equivalent; reads in two integers as strings, converts // to int, computes and prints the sum. //-------------------------------------------------------- public static void main(String[] args) { int intVal; String num1, num2; int sum; Scanner scan = new Scanner (System.in); // Read in an integer and print its binary, octal, // and hex representations System.out.print("Enter an integer: "); intVal = scan.nextInt(); System.out.println(); System.out.println ("The binary representation of " + intVal +
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: " is " + Integer.toBinaryString(intVal) + "."); System.out.println ("The octal representation of " + intVal + " is " + Integer.toOctalString(intVal) + "."); System.out.println("The hexadecimal representation of " + intVal + " is " + Integer.toHexString(intVal) + "."); System.out.println(); // Print the maximum and minimum Java int values System.out.println ("The maximum Java int is " + Integer.MAX_VALUE); System.out.println ("The minimum Java int is " + Integer.MIN_VALUE); System.out.println(); // Read two integers as strings, compute and print the sum System.out.print ("Enter two integers: "); num1 = scan.next(); num2 = scan.next(); sum = Integer.parseInt(num1) + Integer.parseInt(num2); System.out.println("The sum of " + num1 + " and " + num2 + " is " + sum + "."); } }...
View Full Document

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Ask a homework question - tutors are online