Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There are 6 different programs + output required for this assignment. Please Hav

ID: 3677202 • Letter: T

Question

There are 6 different programs + output required for this assignment. Please Have 6 Different snipping photos with programs and outputs. The Class ContDemo in Chapter 3 shows one way to use a for loop to print the even numbers 0 to 100. Write programs that print the same output as that program, but do it in the following ways: Using a for loop that increments the loop control variable by 2 each iteration Using a for loop whose loop control variable goes from 0 to 50.Using a for loop whose loop control variable goes from 100 down to 0. Using an infinite for loop with no conditional expression and exiting the loop with a break statement. Using a while loop. Using a do-while loop. There should be 6 different Snipping photos. One photo for each program A - F. (Conversion from miles to kilometers) Write a program that displays the following table. Keep the tab space formatting. (1 mile is 1.609 kilometers.) Print a blank line every 5 lines.

Explanation / Answer

1.

A.

public class CountDemo{

   public static void main(String[] args) {
      
       // loop increment by 2
       for(int i=0; i<=100; i=i+2){
           System.out.print(i+" ");
       }
       System.out.println();
   }
}

/*

Output:

0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100

*/

B.

public class CountDemo {

   public static void main(String[] args) {
      
       // loop variable goes from 0 to 50
       for(int i=0; i<=50; i++){
           if(i%2==0)
               System.out.print(i+" ");
       }
       System.out.println();
   }
}

/*

Output:

0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50

*/

C.

public class CountDemo {

   public static void main(String[] args) {
      
       // loop variable goes down from 100 to 0
       for(int i=100; i>=0; i--){
           if(i%2==0)
               System.out.print(i+" ");
       }
       System.out.println();
   }
}


/*

Output:

100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 0

*/

D.

public class CountDemo {

   public static void main(String[] args) {
      
       // loop variable goes down from 100 to 0
       int i=0;
       for(; ;){
           if(i%2==0)
               System.out.print(i+" ");
           if(i==100)
               break;
           i++;
       }
       System.out.println();
   }
}

/*

Output:

0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100

*/

E.

public class CountDemo {

   public static void main(String[] args) {
      
       // loop variable goes down from 100 to 0
       int i=0;
       while(i<=100){
           if(i%2==0)
               System.out.print(i+" ");
          
           i++;
       }
       System.out.println();
   }
}


/*

Output:

0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100

*/

F.

public class CountDemo {

   public static void main(String[] args) {
      
       // loop variable goes down from 100 to 0
       int i=0;
       do{
           if(i%2==0)
               System.out.print(i+" ");
          
           i++;
       }while(i<=100);
   }
}


/*

Output:

0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100

*/

2.

public class MilesToKm {

   public static void main(String[] args) {
       // double value formator
       double>        DecimalFormat df = new DecimalFormat("#.000");
       System.out.println("Miles               Kilograms");
       for(int i=1; i<=50; i++){
           if(i!=1 && (i-1)%5 == 0)
               System.out.println();
           System.out.println(i+"               "+df.format(i*oneMile));
          
       }
   }
}

/*

Output:

Miles          Kilograms
1               1.609
2               3.218
3               4.827
4               6.436
5               8.045

6               9.654
7               11.263
8               12.872
9               14.481
10               16.090

11               17.699
12               19.308
13               20.917
14               22.526
15               24.135

16               25.744
17               27.353
18               28.962
19               30.571
20               32.180

21               33.789
22               35.398
23               37.007
24               38.616
25               40.225

26               41.834
27               43.443
28               45.052
29               46.661
30               48.270

31               49.879
32               51.488
33               53.097
34               54.706
35               56.315

36               57.924
37               59.533
38               61.142
39               62.751
40               64.360

41               65.969
42               67.578
43               69.187
44               70.796
45               72.405

46               74.014
47               75.623
48               77.232
49               78.841
50               80.450

*/