

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


int total = 10, count = 4.0; float average = 6.67; average = total / count; System.out.println(average); average = (float)total / count; System.out.println(average); average = total / (float)count; System.out.println(average); average = (float)(total / count); System.out.println(average);
Not correct! The first two lines should be: int total = 10, count = 4; float average = 6.67f;
String s1 = new String(“\tWorld!\n”); String s2 = “Hello”; s3 = s1; System.out.println(“s3: ” + s3); s1 = s2 + s1; System.out.println(“s3: ” + s3); System.out.println(“Length of s1: ” + s1.length()); System.out.println(“Substring: ” + s1.substring(3, 6));
Not correct! Variable s3 should be declared as: String s3 = s1;
import java.text.DecimalFormat; import java.text.NumberFormat; public class FormatDemo { public static void main(String []args) { //create DecimalFormat object DecimalFormat fmt = new DecimalFormat ("0.###"); System.out.println(fmt.format(5.9986)); System.out.println(fmt.format(3.8)); NumberFormat percentFmt = numberFormat.getPercentInstance(); System.out.print(percentFmt.format(0.06)); } }
Not correct! See above.