<p>ACS-1903 Lab 3: printf, DecimalFormat, if Fall 2007</p><p> printf, DecimalFormatter, & if</p><p>Lab 3 is to be done outside of class and lab 3D03. You may use lab 3C13 or your own computing resources to support your work. </p><p>When you are showing the output from a program or code segment you must be precise with repect to the line produced and the number of character positions used up.</p><p>Place your answers on the lab paper itself and hand these in to your instructor (3D15) or to the ACS Office (3D11) on or before 4:00pm Monday Oct 1. There are 6 questions.</p><p>Student Identification</p><p>Student number ______</p><p>Last name ______</p><p>First name ______</p><p>Workstation user id ______</p><p>Email address ______</p><p>1. (See pages 146-148.) Change each of the following to single-line Java statements that use a conditional expression. </p><p> if (a>100) c=100; else c=a; ______</p><p> if (a==100) c=0; else c+=1; ______</p><p> if (a==28) a=1; else a*=2; ______</p><p> if (b<0) a=0; else if (b>100)a=100; else a=b; </p><p>______</p><p>1 ACS-1903 Lab 3: printf, DecimalFormat, if Fall 2007</p><p>2. (See pages 126-130.) Complete the following to find the largest of 3 integers read from Standard Input. Note that you must use a nested if statement.</p><p> import java.util.Scanner; public class FindMaximum { public static void main(String[] args) { Scanner keyboard = new Scanner (System.in); int number1, number2, number3, numberMax; System.out.println("enter 3 numbers: "); number1 = keyboard.nextInt(); number2 = keyboard.nextInt(); number3 = keyboard.nextInt();</p><p>System.out.print("the largest of the 3 numbers " +number1+" "+number2+" and "+number3+" is: "+numberMax); System.out.println(); } }</p><p>3. (See pages 161-164.) What is the output from</p><p>String s = "the string <%25s>"; System.out.printf(s,s);</p><p>______</p><p>4. (See pages 161-164.) What is the output from the following</p><p> int num=6; int r = num % 2; num = num / 2; int s = num % 2; num = num / 2; int t = num % 2; num = num / 2; System.out.printf("%1d%1d%1d", t,s,r);</p><p>______</p><p>2 ACS-1903 Lab 3: printf, DecimalFormat, if Fall 2007</p><p>5. (See pages 161-164.) What is the output from the following</p><p> int num=623; int r = num % 10; num = num / 10; int s = num % 10; num = num / 10; int t = num % 10; num = num / 10; System.out.printf("%1d%1d%1d", t,s,r);</p><p>______</p><p>6. (See pages 155-160.) Consider the following program. </p><p> import java.text.DecimalFormat;</p><p> public class lab03Format { public static void main(String[] args) { double number1 = 12.3; double number2 = 45.6; double number3 = 78.9; String string1, string3;</p><p>DecimalFormat formatter1 = new DecimalFormat("##0"); DecimalFormat formatter2 = new DecimalFormat("000"); DecimalFormat formatter3 = new DecimalFormat("000.00");</p><p> string1 = formatter1.format(number1); System.out.println(string1); System.out.println(formatter2.format(number2)); string3 = formatter3.format(number3); System.out.println(string3); } } What is the output from the above?</p><p>How many objects are created and what are their identifiers (names) in the above code?</p><p>What message (method name) is sent to the DecimalFormat objects in the above code?</p><p>3</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages3 Page
-
File Size-