你的意思是说你不知道"for loop"是什么呢,还是不知道循环体内该写什么?
太难了。。。看不懂。I only know how to write the program with "for loop" to display the letter "I". so I know how to use the "for loop" for very very simply programs. Here is the program for the letter ''I".
public class ASCIIArt {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
System.out.print("Please enter a number to indicate how many stars: \n");
final int MAX_SIZE = 8;
int size = userInput.nextInt();
for (int i = 1; i <= size; i++) {
if (size <=MAX_SIZE){
System.out.println(" *");
}
else{
System.out.println("Invalid entry.");
}
}
How do you use the "for loop" to write the program to display the letter "Z". the height of the letter "Z" changes accordingly when the user enters different numbers.
这个题目里是不是这些字母都是用“*”画出来的?I only know how to write the program with "for loop" to display the letter "I". so I know how to use the "for loop" for very very simply programs. Here is the program for the letter ''I".
public class ASCIIArt {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
System.out.print("Please enter a number to indicate how many stars: \n");
final int MAX_SIZE = 8;
int size = userInput.nextInt();
for (int i = 1; i <= size; i++) {
if (size <=MAX_SIZE){
System.out.println(" *");
}
else{
System.out.println("Invalid entry.");
}
}
How do you use the "for loop" to write the program to display the letter "Z". the height of the letter "Z" changes accordingly when the user enters different numbers.
所有你应该用双层循环,一个长度,一个高度。是的
当时打算学CS还有个原因不用太考虑法语的问题,我也查过health care 行业,感觉法语还是很有必要,需要与人沟通。现在法语也是一大障碍,年龄大了学语言短时间也学不会,而且学过去就忘我也感觉编程不容易学。特别是没有一点基础。我发现我们班上那些觉得编程不难的(不是容易,是不难)都是本地高中毕业生。他们在高中的时候就有学编程的了,只不过是不同的编程语言。
楼主有没有想过在health care行业里找职业呢。如果不喜欢护理类的工作(RCA, LPN, RN)等职业,可以考虑下X-ray Tech, Ultrasound Tech, Med. Lab Tech, Med. Lab assistant, Unit clerk...
I only know how to write the program with "for loop" to display the letter "I". so I know how to use the "for loop" for very very simply programs. Here is the program for the letter ''I".
public class ASCIIArt {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
System.out.print("Please enter a number to indicate how many stars: \n");
final int MAX_SIZE = 8;
int size = userInput.nextInt();
for (int i = 1; i <= size; i++) {
if (size <=MAX_SIZE){
System.out.println(" *");
}
else{
System.out.println("Invalid entry.");
}
}
How do you use the "for loop" to write the program to display the letter "Z". the height of the letter "Z" changes accordingly when the user enters different numbers.
package asciiart;
import java.util.Scanner;
/**
*
* @author zw
* Version 1,0
*/
public class ASCIIArt {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner scanHeight = new Scanner(System.in);
System.out.print("Input the size of the height(better odd, larger than 2): ");
int height = scanHeight.nextInt();
LetterGenerator gen = new LetterGenerator(height);
Scanner scanOption = new Scanner(System.in);
System.out.print("Welcome to My ASCII ART: 1. I; 2. L; 3. T; 4. Z; 5. Quit: ");
int input = scanOption.nextInt();
switch(input) {
case 1:
gen.drawI();
gen.print();
break;
case 2:
gen.drawL();
gen.print();
break;
case 3:
gen.drawT();
gen.print();
break;
case 4:
gen.drawZ();
gen.print();
break;
case 5:
System.out.println("Bye!");
break;
default:
System.out.println("Invalid input!");
break;
}
}
}
package asciiart;
/**
*
* @author zw
*/
public class LetterGenerator {
private final int r;
private final String letter[][];
public LetterGenerator(int r) {
this.r = r;
this.letter = new String[r][r];
for(int i = 0; i < r; i ++) {
for(int j = 0; j < r; j ++) {
letter[j] = " ";
}
}
}
public void drawI() {
for(int i = 0; i < r; i ++) {
letter[r - 1] = "*";
}
}
public void drawL() {
for(int i = 0; i < r; i ++) {
for(int j = 0; j < r; j ++) {
if(i < r) {
letter[0] = "*";
}
if(j < r) {
letter[r - 1][j] = "*";
}
}
}
}
public void drawT() {
int mid = r / 2;
for(int i = 0; i < r; i ++) {
for(int j = 0; j < r; j ++) {
if(i < r) {
letter[mid] = "*";
}
if(j < r) {
letter[0][j] = "*";
}
}
}
}
public void drawZ() {
for(int i = 0; i < r; i ++) {
for(int j = (r - 1); j >= 0; j --) {
if(i == 0 || i == (r - 1)) {
letter[j] = "*";
} else {
letter[r - i - 1] = "*";
}
}
}
}
public void print() {
for(int i = 0; i < r; i ++) {
for(int j = 0; j < r; j ++) {
System.out.print(letter[j]);
}
System.out.println("");
}
}
}