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

ublic class Question_7_String_Contains_Chars { String punctuation = \"!@#$%^&*()

ID: 3880740 • Letter: U

Question

ublic class Question_7_String_Contains_Chars { String punctuation = "!@#$%^&*()"; public static void main(String[] args) { Question_7_String_Contains_Chars pangram = new Question_7_String_Contains_Chars(); String testString = stringInput("Enter the string to test: "); boolean containsChars = pangram.testContainsChars(testString); System.out.println("Does the string contain all the characters? " + containsChars); } public boolean testContainsChars(String testString) { // TODO check if testString contains all the punctuation characters being tested. return false; } } ------------------------------------------------------------------------------ package question7; import static input.InputUtils.intInput; import static input.InputUtils.stringInput; /** * * Write a program that displays a square of characters * of any size, between 1 and 100 characters. * * The user should be able to enter a size, a character, and * your program will use loops to display a square. * * So, if the user enters 4, and the character "%" * your program will display %%%% %%%% %%%% %%%% */

Explanation / Answer

Question_7_String_Contains_Chars.java

import java.util.Scanner;

public class Question_7_String_Contains_Chars {

String punctuation = "!@#$%^&*()";

public static void main(String[] args) {

Question_7_String_Contains_Chars pangram = new Question_7_String_Contains_Chars();

String testString = stringInput("Enter the string to test: ");

boolean containsChars = pangram.testContainsChars(testString);

System.out.println("Does the string contain all the characters? " + containsChars);

}

public boolean testContainsChars(String testString) { // TODO check if testString contains all the punctuation characters being tested.

int count = 0;

for(int i=0;i<punctuation.length();i++) {

if(testString.contains(punctuation.charAt(i)+"") ) {

count++;

}

}

if(count==punctuation.length()) {

return true;

}

return false;

}

public static String stringInput(String str) {

Scanner scan = new Scanner(System.in);

System.out.println(str);

return scan.nextLine();

}

}

Output:

Enter the string to test:
Hai! how are you @Suresh #$%^&*()
Does the string contain all the characters? true

SquareChar.java

import java.util.Scanner;

public class SquareChar {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the size:");

int n = scan.nextInt();

System.out.println("Enter the character:");

char ch = scan.next().charAt(0);

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

for(int j=0;j<n;j++) {

System.out.print(ch);

}

System.out.println();

}

}

}

Output:

Enter the size:
4
Enter the character:
%
%%%%
%%%%
%%%%
%%%%