69期-Java SE-004_循环、数组-001-002
2020-12-13 06:07
标签:cas default ann continue 平均值 for void test 空间 Hello.java Test.java Test2.java Test3.java Test4.java Test5.java Test6.java Test7.java 69期-Java SE-004_循环、数组-001-002 标签:cas default ann continue 平均值 for void test 空间 原文地址:https://www.cnblogs.com/HiJackykun/p/11167095.htmlimport java.util.Scanner;
public class Hello {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = "yes";
int num;
while(str.equals("yes")) {
System.out.print("请输入学生编号:");
num = scanner.nextInt();
switch(num) {
case 1:
System.out.println("张三的成绩为90");
break;
case 2:
System.out.println("李四的成绩为80");
break;
case 3:
System.out.println("王五的成绩为70");
break;
default:
System.out.println("输入有误!");
break;
}
System.out.print("是否继续?yes/no");
str = scanner.next();
}
System.out.println("查询结束");
}
}
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// int num = 0;
// do {
// System.out.println("Hello World");
// num++;
// }while(num
String str;
Scanner scanner = new Scanner(System.in);
do {
System.out.println("张三参加体能测试,跑1000米...");
System.out.print("是否合格?yes/no");
str = scanner.next();
}while(str.equals("no"));
System.out.println("合格,通过测试");
}
}
public class Test2 {
public static void main(String[] args) {
for(int i = 0;i ) {
System.out.println("Hello World");
}
}
}
public class Test3 {
public static void main(String[] args) {
//while循环
int num = 0;
while(num ) {
if(num%2!=0) {
System.out.print(num+",");
}
num++;
}
System.out.println("");
//do-while循环
num = 0;
do {
if(num%2!=0) {
System.out.print(num+",");
}
num++;
}while(num);
System.out.println("");
//for循环
for(int i = 0;i ) {
if(i%2!=0) {
System.out.print(i+",");
}
}
}
}
public class Test4 {
public static void main(String[] args) {
//打印1-6
// for(int i=1;i// System.out.print(i+" ");
// }
// System.out.println("");
// for(int i=1;i// System.out.print(i+" ");
// }
// System.out.println("");
// for(int i=1;i// System.out.print(i+" ");
// for(int j=0;j// for(int i=1;i// System.out.print(i+" ");
// }
// System.out.println("");
// }
for(int i=0;i) {
for(int j=0;j) {
System.out.print(" ");
}
for(int k=i;k) {
System.out.print(k+" ");
}
System.out.println("");
}
for(int i=0;i) {
for(int j=0;j) {
System.out.print(" ");
}
for(int k=2-i;k) {
System.out.print(k+" ");
}
System.out.println("");
}
}
}
public class Test5 {
public static void main(String[] args) {
// int sum = 0;
// for(int i=1;i// sum += i;
// if(sum>50) {
// break;
// }
// }
// System.out.println("1-100的总和是"+sum);
int sum = 0;
for(int i=1;i) {
// if(i%2!=0) {
// sum+=i;
// }
if(i%2==0) {
continue;
}
sum+=i;
}
System.out.println("1-200的奇数之和是"+sum);
}
}
public class Test6 {
public static void main(String[] args) {
//声明数组:数据类型[] 数组名
int[] array1;
String array2[];
//分配内存空间:创建数组必须指定长度,根据长度开辟一串连续的内存空间,长度不能修改
array1 = new int[6];
array2 = new String[7];
//给数组赋值
array1[0] = 50;
array1[1] = 60;
array2[1] = "Hello World";
//使用数组
System.out.println(array1[0]);
}
}
public class Test7 {
public static void main(String[] args) {
// int[] array;
// array = new int[4];
int[] array = new int[4];
array[0] = 179;
array[1] = 182;
array[2] = 168;
array[3] = 176;
System.out.println(array[4]);
// //计算平均值
// double sum = 0;
// for(int i=0;i// sum += array[i];
// }
// System.out.println("平均身高是"+sum/4);
// int[] array1 = {179,182,168,176};
// int[] array1 = new int[4];
// array1 = {179,182,168,176};
}
}
文章标题:69期-Java SE-004_循环、数组-001-002
文章链接:http://soscw.com/essay/32466.html