package com.zhang.struct;
import java.util.Scanner;
public class ifDemo01 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入内容:");
String s = scanner.nextLine();
//equals:判断字符串是否相等
if (s.equals("Hello")){
System.out.println(s);
}
System.out.println("End");
scanner.close();
}
}
package com.zhang.struct;
import java.util.Scanner;
public class ifDemo02 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入成绩:");
int score = scanner.nextInt();
//equals:判断字符串是否相等
if (score>60){
System.out.println("及格");
}else{
System.out.println("不及格");
}
scanner.close();
}
}
package com.zhang.struct;
import java.util.Scanner;
public class ifDemo03 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入成绩:");
int score = scanner.nextInt();
//equals:判断字符串是否相等
if (score<=100 && score<=90){
System.out.println("优秀");
}else if (score<89 && score>=75){
System.out.println("良");
}else if (score<75 && score>=60){
System.out.println("及格");
}else if (score<=60 && score>=0){
System.out.println("不及格格");
}else {
System.out.println("成绩不和法");
}
scanner.close();
}
}
package com.zhang.struct;
public class SwitchDemo01 {
public static void main(String[] args) {
//case 穿透 //switch 匹配一个具体的值
char grade = 'C';
switch (grade){
case 'A':
System.out.println("优秀");
break;// 可选
case 'B':
System.out.println("良好");
break;
case 'C':
System.out.println("及格");
break;
case 'D':
System.out.println("不及格");
break;
case 'E':
System.out.println("继续加油");
break;
default:
System.out.println("未知值");
}
}
}
package com.zhang.struct;
public class SwitchDemo02 {
public static void main(String[] args) {
String name = "张三";
//JDK7的新特性,表达式结果可以是字符串!!!
//字符串的本质还是数字
//反编译 java---class(字节码文件)---反编译(IDEA)
switch (name){
case "张三":
System.out.println("你好");
break;
case "李四":
System.out.println("不好");
break;
default:
System.out.println("弄啥嘞");
}
}
}
package com.zhang.struct;
public class WhileDemo01 {
public static void main(String[] args) {
//输出1~100
int i = 1;
while (i<100){
i++;
System.out.println(i);
}
}
}
package com.zhang.struct;
public class WhileDemo02 {
public static void main(String[] args) {
while (true){
//等待客户端连接
//定时检查
//。。。。。。。
}
}
}
package com.zhang.struct;
public class WhileDemo03 {
public static void main(String[] args) {
//计算1+2+3......+100=?
int i = 0;
int sum=0;
while (i<=100){
sum= sum+i;
i++;
}
System.out.println(sum);
}
}
package com.zhang.struct;
public class DoWhileDemo01 {
public static void main(String[] args) {
int i =0;
int sum = 0;
do{
sum = sum +i;
i++;
}while (i<=100);
System.out.println(sum);
}
}
package com.zhang.struct;
public class DoWhileDemo02 {
public static void main(String[] args) {
int a =0;
while (a<0){
System.out.println(a);
a++;
}
System.out.println("==========================");
do{
System.out.println(a);
a++;
}while (a<0);
//do while 至少运行一次
}
}
package com.zhang.struct;
public class ForDemo01 {
public static void main(String[] args) {
int a = 1; //初始化条件
while (a<=100){
System.out.println(a);
a+=2; //迭代
}
System.out.println("while循环结束");
//初始化条件 //条件判断 //迭代
for (int i=1;i<=100;i++){
System.out.println(i);
}
System.out.println("for循环结束");
// 100.for
//死循环
for (;; ) {
}
}
}
package com.zhang.struct;
public class ForDemo02 {
public static void main(String[] args) {
int oddSum = 0;
int evenSum = 0;
for (int i = 0; i <= 100; i++) {
if (i%2!=0){
oddSum +=i;
}else {
evenSum+=i;
}
}
System.out.println("奇数的和:"+oddSum);
System.out.println("偶数的和:"+evenSum);
}
}
package com.zhang.struct;标签:String,int,System,Demo06,println,public,out From: https://www.cnblogs.com/fenghuahua/p/17290241.html
public class ForDemo03 {
public static void main(String[] args) {
for (int i = 0; i <= 1000; i++) {
if (i%5==0){
System.out.print(i+"\t");
}
if (i%(5*3)==0){
System.out.println();
//System.out.print("\n");
}
}
//println 输出完会换行
//print 输出完不会换行
}
}