help? math pnw.edw-rkraltics 12300cs_ 12300 Exam_2 Review java 10302017 c) Creat
ID: 3607184 • Letter: H
Question
help?
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--;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.