Write a program that displays to the screen a square 10x10 of “S” characters. Use “while” loop. Don’t separate characters in the same line. package com.javarush.test.level04.lesson10.task04; ✓ The program is compiled without errors. ✗ The program runs correctly but it has not pass testing. This is program output during runtime:

import java.io.*;

/* S-square
Write a program that displays to the screen a square 10x10 of “S” characters. Use “while” loop.
    Don’t separate characters in the same line.
*/

public class Solution
{
    public static void main(String[] args) throws Exception
    {
        int a = 1;
        for (int i = 1; i < 11; i++){
            while (a < 11){
                System.out.print("S");
                a++;
            }
            if (i < 10) {
                System.out.println();
            }
            else {
                break;
            }
            a=1;
        }
    }
}

asked 12 Apr '15, 06:40

Karolis%20Belia%C5%A1as's gravatar image

Karolis Beli...
25310
accept rate: 0%

Don't use 'for' loop, use 'while' loop. You don't need to initialize if/else statement, because your println() method will run just after nested while loop. Your 'int a' variable should be placed inside outer 'while' loop.

(12 Apr '15, 08:31) Andrey

Don't use 'for' loop, use 'while' loop. You don't need to initialize if/else statement, because your println() method will run just after nested while loop. Your 'int a' variable should be placed inside outer 'while' loop. Your inner loop is OK, well done :)

link

answered 12 Apr '15, 08:33

Andrey's gravatar image

Andrey
1323
accept rate: 35%

edited 12 Apr '15, 08:35

here is the answear .

int number = 10;
int row = 0;
int col = 0;
while (row < number)
{
    col = 0;
    while (col < number)
    {
        System.out.print("S");
        col++;
    }
    System.out.println();
    row++;
}
System.out.println();
row++;
link

answered 30 Apr '15, 16:13

Muhammad%20Hassan%20Durrani's gravatar image

Muhammad Has...
4311324
accept rate: 0%

int a = 10, b = 10;

    while(a>0){
        while(b>0){
            System.out.print("S");
            b--;
        }
        System.out.println();
        a--;
        b=10;
    }

Its shorter than above and have 1 less variable.

link

answered 23 Jul '17, 06:33

YourDoom's gravatar image

YourDoom
1811
accept rate: 35%

edited 23 Jul '17, 06:33

This is solution:

 public static void main(String[] args) throws Exception
    {
        int i = 1;
        while(i <= 10)
        {
            int j = 1;
            while(j <= 10)
            {
                System.out.print("S");
                j++;
            }
            System.out.println();
            i++;
        }
    }

link

answered 06 Jul, 04:02

blacklight's gravatar image

blacklight
11
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×69
×36
×15
×7

Asked: 12 Apr '15, 06:40

Seen: 1,985 times

Last updated: 06 Jul, 04:02