锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
]]>
]]>
]]>
]]>
]]>
濡傛灉鐢╟ontinue榪斿洖,濡傛灉鏉′歡婊¤凍鎵цcontinue, 璺沖嚭涓嬮潰璇彞鐨勬墽琛?鑰岃繑鍥炲埌for 璇彞鐨勫紑澶?鍐嶆鍒ゆ柇for涓殑鏉′歡,浠庤屾牴鎹潯浠舵墽琛屽叾涓殑寰幆浣撳唴瀹廣?br>
綆鍗曞湴璇達(dá)紝姣斿榪欐牱涓涓▼搴忥細(xì)
for(...) {
...
continue/break;
...
}
System.out.prinln("a");
continue琛ㄧず绔嬪嵆鍘繪墽琛?#8220;for(...)”榪欒浠g爜錛宐reak琛ㄧず绔嬪嵆鍘繪墽琛?#8220;System.out.prinln("a");”榪欒浠g爜銆傛垜闅忔墜鍐欎簡涓孌電▼搴忥紝浣犵湅鐪嬪彲鑳借兘甯姪浣犵悊瑙c?
public class BreakTest {
public static void main(String args[]) {
System.out.println("寰幆娌℃湁寮濮?);
System.out.println("鐜板湪寮濮嬫祴璇昪ontinue");
for (int i = 0; i < 3; i++) {
System.out.println("寮濮嬬" + i + "嬈or寰幆");
if (i == 1) {
continue;
}
System.out.println("鐪嬬湅continue鍚庤繖閲屾墽琛屼簡鍚楋紵");
}
System.out.println("continue嫻嬭瘯瀹屾瘯\n***********************");
System.out.println("鐜板湪寮濮嬫祴璇昩reak");
for (int i = 0; i < 3; i++) {
System.out.println("寮濮嬬" + i + "嬈or寰幆");
if (i == 1){
break;
}
System.out.println("鐪嬬湅break鍚庤繖閲屾墽琛屼簡鍚楋紵");
}
System.out.println("break嫻嬭瘯瀹屾瘯\n***********************");
}
}
1. break 涓?nbsp;continue 鍔犳爣絳劇敤娉?br>鍦↗ava璇彞閲岋紝鍞竴鑳芥斁鏍囩鐨勫湴鏂規(guī)槸鍦ㄥ驚鐜鍙ュ墠闈€傝屼笖寰幆璇彞璺熸爣絳句箣闂翠笉鑳芥湁浠諱綍涓滆タ銆?br>label1:
outer-iteration {
inner-iteration {
//...
break; // 1
//...
continue; // 2
//...
continue label1; // 3
//...
break label1; // 4
}
}
妗堜緥1浼?xì)涓柇鍐呴儴弩@鐜?浼?xì)涓柇鍐呴儴褰撳墠弩@鐜紝鐩存帴璺沖叆涓嬩竴杞驚鐜傛渚?涓柇鍐呴儴鍜屽閮ㄥ驚鐜紝璺沖埌l(fā)abel1錛屼粠澶栭儴寮澶撮噸鏂板紑濮嬪驚鐜傛渚?璺沖埌l(fā)abel1錛屼笖涓嶅湪榪涘叆寰幆銆?br>
涓嬮潰涓句緥錛?br>
public class LabeledFor {
static Test monitor = new Test();
public static void main(String[] args) {
int i = 0;
outer: // Can't have statements here
for(; true ;) { // infinite loop
inner: // Can't have statements here
for(; i < 10; i++) {
System.out.println('i = ' + i);
if(i == 2) {
System.out.println('continue');
continue;
}
if(i == 3) {
System.out.println('break');
i++; // Otherwise i never
// gets incremented.
break;
}
if(i == 7) {
System.out.println('continue outer');
i++; // Otherwise i never
// gets incremented.
continue outer;
}
if(i == 8) {
System.out.println('break outer');
break outer;
}
for(int k = 0; k < 5; k++) {
if(k == 3) {
System.out.println('continue inner');
continue inner;
}
}
}
}
}
} ///:~
緇撴灉:
'i = 0',
'continue inner',
'i = 1',
'continue inner',
'i = 2',
'continue',
'i = 3',
'break',
'i = 4',
'continue inner',
'i = 5',
'continue inner',
'i = 6',
'continue inner',
'i = 7',
'continue outer',
'i = 8',
'break outer'
]]>
]]>
import javax.swing.JOptionPane;
public class taxQuestion
{
public static void main(String[] args)
{
//杈撳叆鍩哄噯鍊?br> String statusString=JOptionPane.showInputDialog(null,"Enter the filing status:\n"+"(0-single filer,1-married jointly,\n)"+"2-married separately,3-head of household)","Input a status",JOptionPane.QUESTION_MESSAGE);
int status=Integer.parseInt(statusString);
//杈撳叆鏀跺叆鍊?br> String incomeString=JOptionPane.showInputDialog(null,"Enter the taxable income:","Give me your money",JOptionPane.QUESTION_MESSAGE);
Double income=Double.parseDouble(incomeString);
double tax=0;
if(status==0)
{
if(income<=1200)
JOptionPane.showMessageDialog(null,"You should not pay for the tax!","The show of the result",JOptionPane.INFORMATION_MESSAGE);
else if(income<=3000)
{
tax=(income-1200)*0.10;
JOptionPane.showMessageDialog(null,"You should pay"+tax+"for the tax!","The show of the result",JOptionPane.INFORMATION_MESSAGE);
}
else if(income<=10000)
{
tax=(income-3000)*0.15;
JOptionPane.showMessageDialog(null,"You should pay"+tax+"for the tax!","The show of the result",JOptionPane.INFORMATION_MESSAGE);
}
else if(income<300000)
{
tax=(income-10000)*0.30;
JOptionPane.showMessageDialog(null,"You should pay"+tax+"for the tax!","The show of the result",JOptionPane.INFORMATION_MESSAGE);
}
else
{
tax=(income-300000)*0.80;
JOptionPane.showMessageDialog(null,"You should pay"+tax+"for the tax!","The show of the result",JOptionPane.INFORMATION_MESSAGE);
}
}
else
{
tax=(income-status);
JOptionPane.showMessageDialog(null,"You should pay"+tax+"for the tax!","The show of the result",JOptionPane.INFORMATION_MESSAGE);
}
}
}
/////////////////////////////////////////////////////////////////////////
嫻嬭瘯緇撴灉綆瑕佸涓嬶細(xì)
////////////////////////////////////////////////////////////////////////
int year=Integer.parseInt(yearString);
//鍒ゆ柇鏄惁涓虹憺騫?br> boolean isLeapYear=((year%4 ==0)&&(year%100!=0))||(year%400==0);
JOptionPane.showMessageDialog(null,year+"is a leap year?"+isLeapYear,"Example 2.1 Output
(int)",JOptionPane.INFORMATION_MESSAGE);
String doubleString=JOptionPane.showInputDialog(null,"Enter a double value","Example 2.1 Input
(double)",JOptionPane.QUESTION_MESSAGE);
double doubleValue=Double.parseDouble(doubleString);
JOptionPane.showMessageDialog(null,doubleValue+"is positive?"+(doubleValue>0),"Example 2.1 Output
(double)",JOptionPane.INFORMATION_MESSAGE);
}
}
public class Triangle extends GeometricObject
{
private double side1=1.0;
private double side2=1.0;
private double side3=1.0;
//鏃犲弬鏋勯犲櫒
public Triangle()
{
this(1.0,1.0,1.0,"red",false);
}
public Triangle(double side1,double side2,double side3)
{
this(side1,side2,side3,"red",false);
}
//鏈夊弬鏋勯犲櫒
public Triangle(double side1, double side2,double side3,String color,boolean filled)
{
super(color,filled);
this.side1=side1;
this.side2=side2;
this.side3=side3;
}
//瀹氫箟Side1鐨凣et鍜孲et鏂規(guī)硶
public double getSide1()
{
return side1;
}
public void setSide1(double side1)
{
this.side1=side1;
}
//瀹氫箟Side2鐨凣et鍜孲et鏂規(guī)硶
public double getSide2()
{
return side2;
}
public void setSide2(double side2)
{
this.side2=side2;
}
//瀹氫箟Side3鐨凣et鍜孲et鏂規(guī)硶
public double getSide3()
{
return side3;
}
public void setSide3(double side3)
{
this.side3=side3;
}
//姹傞潰縐?br> public double getArea()
{
double p;
p=(side1+side2+side3)/2;
double s;
s=Math.sqrt(p*(p-side1)*(p-side2)*(p-side3));
return s;
}
//璁$畻鍛ㄩ暱
public double getPerimeter()
{
return (side1+side2+side3);
}
//瀹氫箟toString鏂囨湰璇存槑
public String toString()
{
return "Triangle: side1 = " + side1 + " side2 = " + side2 +" side3 = " + side3;
}
public static void main(String[] args)
{
Triangle tr = new Triangle(3.6,5.8,3.5);
System.out.println("The perimeter of Triangle is :"+tr.getPerimeter());
System.out.println("The area of Triangle is :"+tr.getArea());
System.out.println("The color of Triangle is :"+tr.getColor());
System.out.println("The filled of Triangle is :"+tr.isFilled());
}
}