has to work with java! Create a program that asks the user for some information
ID: 3760667 • Letter: H
Question
has to work with java!
Create a program that asks the user for some information and creates a design of *, [], |, #s, or whatever utilizing nested loops based off of that information given by the user. Try to create something that you think looks good, and that uses the input
Needed for this design:
Get input from user
Check input to make sure it is feasible
Nested loops that use the input
Comments on the loops that identify the parts of the loops and what they control
Output based off of the loops
Explanation / Answer
package mani;
import java.util.Random;
import java.util.Scanner;
public class crapsSimulator {
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
System.out.print("Enter the character you want to print: ");
String t=scan.next();
System.out.println("Number of lines: ");
int n=scan.nextInt();
if(n<0){
System.out.println("Input is negative!!!");
}else{
if(t.equals("*")||t.equals("[]")||t.equals("|")||t.equals("#$")){
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
System.out.print(t); }
System.out.println();
}
}
else{
System.out.println("Invalid character!!");
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.