杭电ACM2052java做法
2015-08-30 10:03
459 查看
Picture
Problem Description
Give you the width and height of the rectangle,darw it.
Input
Input contains a number of test cases.For each case ,there are two numbers n and m (0 < n,m < 75)indicate the width and height of the rectangle.Iuput ends of EOF.
Output
For each case,you should draw a rectangle with the width and height giving in the input.
after each case, you should a blank line.
Sample Input
3 2
Sample Output
+---+
| |
| |
+---+
感觉这道题比较水吧,我没想啥好办法,就直接打了
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner scanner=new Scanner(System.in);
while(scanner.hasNextInt()){
int a=scanner.nextInt();
int b=scanner.nextInt();
for(int i=0;i<b+2;i++){
if(i==0||i==b+1){
System.out.print("+");
for(int j=1;j<a+1;j++){
System.out.print("-");
}
System.out.println("+");
}
else{
System.out.print("|");
for(int j=1;j<a+1;j++){
System.out.print(" ");
}
System.out.println("|");
}
}
System.out.println();
}
}
}
Problem Description
Give you the width and height of the rectangle,darw it.
Input
Input contains a number of test cases.For each case ,there are two numbers n and m (0 < n,m < 75)indicate the width and height of the rectangle.Iuput ends of EOF.
Output
For each case,you should draw a rectangle with the width and height giving in the input.
after each case, you should a blank line.
Sample Input
3 2
Sample Output
+---+
| |
| |
+---+
感觉这道题比较水吧,我没想啥好办法,就直接打了
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner scanner=new Scanner(System.in);
while(scanner.hasNextInt()){
int a=scanner.nextInt();
int b=scanner.nextInt();
for(int i=0;i<b+2;i++){
if(i==0||i==b+1){
System.out.print("+");
for(int j=1;j<a+1;j++){
System.out.print("-");
}
System.out.println("+");
}
else{
System.out.print("|");
for(int j=1;j<a+1;j++){
System.out.print(" ");
}
System.out.println("|");
}
}
System.out.println();
}
}
}
相关文章推荐
- Java 内存区域和GC机制
- Spring MVC 是什么
- HP JAVA第一周
- java实现9*9乘法表
- Spring 注解@Transactional readOnly=true
- 《JAVA 核心技术 基础知识》 内部类 笔记
- Java记录 -15- 面向对象之多态续
- java多线程:线程间的通信-生产者和消费者(三)
- Java数组操作的10大方法
- 【J2SE】Java简介
- java多线程
- JVM学习—内存方区域与内存溢出异常
- java 基础学习总结(附带eclipse一些常用操作)
- 在MyEclipse中建立Maven项目
- 【java】初始化和清理
- Java compiler与installed Java project face不匹配解决方法
- java 自动装箱自动拆箱
- UBUNTU 查看 JAVA安装路径
- Java 7 并发编程实战手册目录
- 从零开始学Java之出入门卫管理系统(四)