Looping Strings in Java using while loop | Ask The Code

Basic Java Programming | CodeChum Java Solutions | AskTheCode


Looping strings works like playing a broken record – it repeats something over and over again. But what's great about loops is that we can define as to how many times it will repeat something with proper code, and that's what we're about to do now using while() loops.


Scan a positive integer and store it in a variable. Using while() loop, repeatedly print out "CodeChum is awesome" for the same number of times as that of the inputted integer.

And each outputted string must be separated in new lines.

Input Sample:


Output Sample:

CodeChum is awesome

CodeChum is awesome

CodeChum is awesome

CodeChum is awesome


import java.util.Scanner;

public class loopingStrings{

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

String a = "CodeChum is awesome";

int n = sc.nextInt();

while(n != 0){






134 views0 comments

Recent Posts

See All

Golf CodeChef Solution in Java - AskTheCode

CodeChef May Long Challenge Solution | Golf (LKDNGOLF) solution | AskTheCode Golf (LKDNGOLF) solution Problem: It's a lockdown. You’re bored in your house and are playing golf in the hallway. The hall

Solubility - CodeChef Solution in Java and C++| AskTheCode

CodeChef May Long Challenge Solution | Solubility (SOLBLTY) solution | AskTheCode Solubility (SOLBLTY) solution Problem: Suppose for a unit rise in temperature, the solubility of sugar in water increa

Valid Paths CodeChef Solution in C++ | AskTheCode

CodeChef May Long Challenge Solution | Valid Paths (VPATH) solution | AskTheCode Valid Paths (VPATH) CodeChef solution Problem: You are given a tree with N nodes numbered from 1 to N. A set S of nodes