Lab04.java - String bitString2 = binary.substring 1,2...

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

View Full Document Right Arrow Icon
/*My name is Elisha Steiner and the due date is 3/8/16 The purpose of this lab, is to use the substring method to extract each character into its own substring */ public class Lab04 { //Main method public static void main ( String [] args ) { String binaryValue = ( "0011" ); int decimalValue = convertToDecimal ( binaryValue ); System.out.println( "the binary number is: " + binaryValue + "." ); System.out.println( "The decimal equivalent number is: " + decimalValue + "." ); String Value = ( "Java is the language" ); String Mix = rephrase( Value); System.out.println( "The origional value was " + Value ); System.out.println( "The new sentence is: " + Mix ); } //Integer.parseInt method public static int convertToDecimal ( String binary ) { String bitString1 = binary.substring( 0,1 );
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: String bitString2 = binary.substring( 1,2 ); String bitString3 = binary.substring( 2,3 ); String bitString4 = binary.substring( 3,4 ); int bit1 = Integer.parseInt( bitString1 ); int bit2 = Integer.parseInt( bitString2 ); int bit3 = Integer.parseInt( bitString3 ); int bit4 = Integer.parseInt( bitString4 ); int bitFinal =bit1*8 + bit2*4 + bit3*2 + bit4*1; return bitFinal; } //Rephrase method public static String rephrase ( String sentence ) { String Value = ( "Java is the language" ); String Mix1 = Value.substring(0,Value.indexOf(" ")); String Mix2 = Value.substring(Value.indexOf(" ")+1); String Top = Mix2.substring(0,1).toUpperCase(); String Bottom = Mix2.substring(1); String Together = Top + Bottom + (" ") + Mix1; return Together; } }...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern