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 student.xiaoqiao.day01;

import java.util.Scanner;

public class Yi {

public static void main(String[] args) {

System.out.println("请输入一个数");

Scanner sc = new Scanner(System.in);

int x = sc.nextInt();

if (x < 1) {

System.out.println("y=" + x);

}

if (x > 1 & x < 10) {

System.out.println("y=" + (2 * x - 1));

}

if (x > 10) {

System.out.println("y=" + (3 * x - 11));

}

}

}

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

package student.xiaoqiao.day01;

import java.util.Scanner;

public class Er {

public static void main(String[] args) {

System.out.println("请输入年份");

Scanner sc=new Scanner(System.in);

int year=sc.nextInt();

if((year%4==0&year%100!=0)|(year%400==0))

System.out.println("是闰年");

else

System.out.println("不是闰年");

}

}

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

package student.xiaoqiao.day01;

import java.util.Scanner;

public class San {

public static void main(String[] args) {

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

Scanner sc = new Scanner(System.in);

int x = sc.nextInt();

int y = sc.nextInt();

int z = sc.nextInt();

if (x > y & x > z) {

System.out.println(x);

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

System.out.println(y);

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

System.out.println(z);

}

}

}

4_1输出图形

*

***

*****

package student.xiaoqiao.day01;

public 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++) {

System.out.print("");

}

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

System.out.print("*");

}

System.out.print('\n');

}

}

}

4_2输出图形

*****

***

*

package student.xiaoqiao.day01;

public 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++) {

System.out.print("");

}

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

System.out.print("*");

}

System.out.print('\n');

}

}

}

4_3输出图形任意输入n

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

当输入n值为2时,输出

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

当输入n值为5时,输出

*

***

*****

*******

*********

*******

*****

***

*

package student.xiaoqiao.day01;

import java.util.Scanner;

public class Si_3 {

public static void main(String[] args) {

System.out.println("请输入一个数:");

Scanner sc=new Scanner(System.in);

int temp = sc.nextInt();

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

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

System.out.print("");

}

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

System.out.print("*");

}

System.out.print('\n');

}

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

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

System.out.print("");

}

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

System.out.print("*");

}

System.out.print('\n');

}

}

}

4_4 输出图形

***

相关文档
最新文档