java基础作业1附答案

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1. X (x<1)

Y= 2x-1 (1

3x-11 (x>10) 要求输入x值后,输出y值。package ;

public class Yi {

public static void main(String[] args) {

"请输入一个数");

Scanner sc = new Scanner;

int x = ();

if (x < 1) {

"y=" + x);

}

if (x > 1 & x < 10) {

"y=" + (2 * x - 1));

}

if (x > 10) {

"y=" + (3 * x - 11));

}

}

}

2.输入一个年份判断year是否是闰年

package class Er {

public static void main(String[] args) {

"请输入年份");

Scanner sc=new Scanner;

int year=();

if((year%4==0&year%100!=0)|(year%400==0)) "是闰年");

else

"不是闰年");

}

}

3.任意输入a,b,c 3个数判断a,b,c大小

package class San {

public static void main(String[] args) {

"请输入三个数(加空格或回车):");

Scanner sc = new Scanner;

int x = ();

int z = ();

if (x > y & x > z) {

} else if (x < y & z < y) {

} else if (x < z & y < z) {

}

}

}

4_1输出图形

*

***

*****

package class Si_1 {

public static void main(String[] args) {

int temp = 3;

for (int i = 1; i <= temp; i++) {

for (int j = 1; j <= temp - i; j++) {

}

for (int k = 1; k <= 2 * i - 1; k++) {

"*");

}

'\n');

}

}

}

4_2输出图形

*****

***

*

package class Si_1 {

public static void main(String[] args) {

int temp = 3;

for (int i = 1; i <= temp; i++) {

for (int j = 1; j <= temp - i; j++) {

}

for (int k = 1; k <= 2 * i - 1; k++) {

"*");

}

'\n');

}

}

}

4_3输出图形任意输入n

当输入n值为1时,输出 *

当输入n值为2时,输出

当输入n值为3时,输出 .。。。。。

当输入n值为5时,输出

*

***

*****

*******

*********

*******

*****

***

*

package class Si_3 {

public static void main(String[] args) {

"请输入一个数:");

Scanner sc=new Scanner;

int temp = ();

for (int i = 1; i <= temp; i++) {

for (int j = 1; j <= temp - i; j++) {

" ");

}

for (int k = 1; k <= 2 * i - 1; k++) {

"*");

}

'\n');

}

for (int i = temp; i >= 1; i--) {

for (int j = i-1; j < temp; j++) {

" ");

}

for (int k = 1; k <= 2 * i - 3; k++) {

}

'\n');

}

}

}

4_4 输出图形

***

*****

*******

package class Si_4 {

public static void main(String[] args) {

int temp = 3;

for (int i = 1; i <= temp; i++) {

for (int j = 1; j <= temp - i; j++) {

" ");

}

for (int k = 1; k <= 2 * i + 1; k++) {

相关文档
最新文档