- /** Loops/Strings Test
name _________________________ */
- public class LoopsQuiz{
- public static void main(String[]args){
- int x = 0, y =
0, z = 1, n1 = 2, n2 = 2, t = 0;
-
- // Give the values of the variables after the loops have
run.///////////////////////////////
- for (x=0; x<=n1;
x++) {
-
for (y=0; y<=n2; y++) {
-
z += 2;
-
t += 3;
-
}
- }
-
System.out.println("1) x = "+x +"; y = "+y +"; z = "+z
+"; t = "+t );
- //
- // 1) x = ________
y = ________ z = ________ t = ________
-
- n1 = 2; n2 = 2;
z = 4; t = 0;
- for (x=0; x<=n1;
x++){
-
for (y=0; y<=n2; y++){
-
z *= 2;
-
t++;
-
}
- }
-
System.out.println("2) x = "+x +"; y = "+y +"; z = "+z
+"; t = "+t );
- //
- // 2) x = ________
y = ________ z = ________ t = ________
-
-
- n1 = 2; n2 = 3;
z = 1; t = 0;
- for (x=1; x<=n1;
x++){
-
for (y=1; y<=n2; y++){
-
z += y;
-
t++;
-
}
- }
-
System.out.println("3) x = "+x +"; y = "+y +"; z = "+z
+"; t = "+t );
- //
- // 3) x = ________
y = ________ z = ________ t = ________
- n1 = 2; n2 = 2;
z = 1; t = 5;
- for (x=1; x<=n1;
x++){
-
for (y=1; y<=n2; y++){
-
z *= y + x;
-
}
- }
-
System.out.println("4) x = "+x +"; y = "+y +"; z = "+z
+"; t = "+t );
- //
- // 4) x = ________
y = ________ z = ________ t = ________
-
-
- n1 = 2; n2 = 2;
z = 1; t = 0;
- for (x=1; x<=n1;
x++){
-
for (y=1; y<=n2; y++){
-
t++;
-
z += y * x;
-
if (z > 3){
-
z = 2;
-
break;
-
}
-
}
- }
-
-
System.out.println("5) x = "+x +"; y = "+y +"; z = "+z
+"; t = "+t );
- //
- // 5) x = ________
y = ________ z = ________ t = ________
-
-
- n1 = 2; n2 = 3;
z = 1; t = 0;
- for (x=0; x<=n1;
x++){
-
for (y=0; y<=n2; y++){
-
z *= y;
-
t++;
-
}
-
t++;
- }
-
System.out.println("6) x = "+x +"; y = "+y +"; z = "+z
+"; t = "+t );
- //
- // 6) x = ________
y = ________ z = ________ t = ________
-
- // Write the output for the following:
- // 7)
- n1 = 4; n2 = 3;
- for (x=0; x<n1;
x++){
-
for (y=0; y<n2; y++) System.out.print(" x");
-
System.out.println(" ");
- }
-
System.out.println(" ");
-
- String s1
= "cat" ,
-
s2 = "Cats" ,
-
s3 = "cap" ,
-
s4 = "cat " ,
-
s5 = "cats" ;
- // List the value returned.
-
- /* ______ 8) */ System.out.println (s1.compareTo ( s2 )
) ;
-
- /* ______ 9) */ System.out.println (s1.compareTo ( s4 )
) ;
-
- /* ______ 10) */ System.out.println (s1.compareTo ( s3 )
) ;
- /* ______ 11) */ System.out.println (s2.compareToIgnoreCase
( s5 ) ) ;
-
- //
12) Write a program that uses command line input to input a string
representing a social security number
- //
with no dashes in it. The program then output the social security number with
dashes in it.
- //
Example: if 222334444 is input, the program will output
222-33-4444.
-
}
- }