Java-break与continue

break的

package adsf;
import java.util.*;
public class dst {
	public static void main(String[] args) {
	Scanner input=new Scanner(System.in);
	System.out.print("请输入一个值:");
	int s=input.nextInt();
	System.out.println("根据这个值输出的加法表为:");
	for(int i=0,j=s;i<=s;i++,j--) {
		
		System.out.println(i+"+"+j+"="+(i+j));
		
		
	}
  }
}	
---------------------------------
package adsf;

public class ddd {
	public static void main(String[] args) {
		int sum=0;
	for(int i=1;i<=100;i++) {
		if(i%7==0) {
			sum=sum+i;}
		
			if(sum>30) {
				System.out.println("i="+i);
				break ;
			}
			
		} 
		System.out.println("sum="+sum);
		
	}

}

continue的

package adsf;
public class ddd {
	public static void main(String[] args) {
		int sum=0;
	for(int i=1;i<=100;i++) {
		if(i%7==0) {
			continue;
	}
		sum=sum+i;
		
		} 
		System.out.println("sum="+sum);
	}
}
------------------------------------------
package adsf;
public class ddd {
	public static void main(String[] args) {
		int sum=0;
	for(int i=1;i<=100;i++) {
		if(i%3==0||i%10==2||i%10==3||i%10==4||i%10==7) {
			continue;
	}
		sum=sum+i;
		
		} 
		System.out.println("sum="+sum);
	}
}
--------------------------------------
package adsf;
public class ddd {
	public static void main(String[] args) {
		int sum=0;
	for(int i=1;i<=100;i++) {
		if(i%3==0||i%10==2||i%10==3||i%10==4||i%10==7) {
			continue;
	}
		sum=sum+i;
		if(sum>1800) {
			System.out.println("i="+i);
			break;
		}
		
		} 
		System.out.println("sum="+sum);
	}
}

 

你可能感兴趣的:(java-基础)