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

help? math pnw.edw-rkraltics 12300cs_ 12300 Exam_2 Review java 10302017 c) Creat

ID: 3607184 • Letter: H

Question


help?

math pnw.edw-rkraltics 12300cs_ 12300 Exam_2 Review java 10302017 c) Create the following six lines of output Problem 3) Write a single while-loop that uses these two strings, string s1... String s2 " to create the following 12 1ines of output. Problem 4) Write two nested while-loops that create the following 12 lines of output. Problem 5) Draw the following 11 line pictúre using as, little code as possible. +84*4* 94*44 Problem 6) Each of the following two program segments prints out the first ten odd integers int n = 10, i=-1; while (1

Explanation / Answer

3)


public class Patten1 {

    public static void main(String[] args) {
   int i, j, rows;
   String s1 = "************";
String s2 = " ";
rows = s1.length();
   for(i=1; i<=rows; i++)
    {
        /* Print leading spaces */
        for(j=1; j<i; j++)
        {
            System.out.print(s2);
        }

        /* Iterate through columns to print star */
        for(j=i; j<=rows; j++)
        {
            System.out.print(s1.charAt(i-1));
        }

        /* Move to next line */
        System.out.println();
    }
    }
}
   

4)

public class Pattern {

    public static void main(String[] args) {
      
    String s1 = "************";
   String s2 = " ";
       int ro = s1.length();
   int r = s2.length();
   int i=0,j;

   while(i< ro){
   j=1;
   while(j< i){
   System.out.print(s1.charAt(j)); j++; }
   System.out.println();
   i++;
   }
      

    }
}
   

5)

public class Mainan
{
   public static void main(String[] args) {
String s1 = "***********";
        int len = s1.length();         
        String s2 = "";
        for (char c : s1.toCharArray()) {
            s2+= s2.length() > 0 ? " " + String.valueOf(c) : String.valueOf(c);
            System.out.printf("%" + (len + s2.length() - 1) + "s ", s2);
            len--;
        }
}
}