Computer Science, asked by mdasraf1235543, 4 months ago

print the following pattern with the for loop
#
#@
#@#
#@#@​

Answers

Answered by jaikaransingh2007
1

Answer:

Output:

#

#@

#@#

#@#@

Explanation: Code in java (Pls write classes on your own)

public static void main(String args[]){

Scanner s = new Scanner(System.in);

String last = "#"; //stores the last string in the pattern

System.out.println(last);

for(int i = 0; i < 3; i++){

if(last.endsWith("#")){

String a = last + "@";

System.out.println(a);

last = a;

} else{

String b = last + "#";

System.out.println(b);

last = b;

}

}

}

Similar questions