break和continue只能在循环内部使用。你现在的这种情况可以使用goto

解决方案 »

  1.   

    java虽然将goto作为保留字,但它根本就不支持goto语句
      

  2.   

    刚刚看得java编程思想,标签不是随便哪都可以定义的,具体要求我也不是很清楚。
      

  3.   

    goto在JAVA里只是保留字,不能使用的。
      

  4.   

    不好意思 前几天有事没来得及
    我改为goto后 还是在最后跳转的时候出现问题  
    illegal start of expression     goto read_new1
    illegal start of expression     goto read_new2
    goto在java中确实是保留字,但有没有别的跳转方式???
      

  5.   

    从新逻辑:
              do{
              balance+=payment;
              interest=balance*interestRate/100;
              balance+=interest;
              year++;
              System.out.println("After "+year+" later,your balance is "+balance);
              input=JOptionPane.showInputDialog
              ("Do you want to retirement?(Y/N)");
     if(input.equals("N")
      continue;
    else if(input.equals("Y")) {
              System.out.println(year+" you retire and your balance is "+balance);
              System.exit(0);
    }else{
               do{ 
                input=JOptionPane.showInputDialog
                ("pls enter again:Do you want to retirement?(Y/N)");
                if(input.equals("N"))
                break;     //出错 提示undefined lable: read_new1
                }while(TRUE);
    }
      }while(input.equals("N"));
      

  6.   

    java不支持goto语句的.
    continue只能循环内部使用.
    break可以在循环外部使用.
      

  7.   

    to: layer781010 请问最后while(TURE)是什么意思?
    修改了程序如下,能运行,但当出现连续2次或以上错误输入时,有问题
    要象这样,是不是最后倒数第八行else continue  这样写有问题,continue跳转到哪里
    ////////////////////////////////程序
    import java.text.*;
    import javax.swing.*;public class Retirement{
        public static void main(String[] args){
            String input=JOptionPane.showInputDialog
            ("how much money will you contribute every years:");
            double payment=Double.parseDouble(input);        input=JOptionPane.showInputDialog
            ("interest rate in %:");
            double interestRate=Double.parseDouble(input);        NumberFormat formatter=NumberFormat.getCurrencyInstance();        double balance=0,interest=0;
            int year=0;
              
            do
            {
              balance+=payment;
              interest=balance*interestRate/100;
              balance+=interest;
              year++;
              System.out.println("After "+year+" later,your balance is "+formatter.format(balance));
              input=JOptionPane.showInputDialog
              ("Do you want to retirement?(Y/N)");
              input=input.toUpperCase();
              if(input.equals("N"))
              continue;
              else if(input.equals("Y"))
              {
              System.out.println(year+"year later you retire and your balance is "+formatter.format(balance));
              System.exit(0);
              }
              else
              {
               do{
                  input=JOptionPane.showInputDialog
                  ("pls enter again:Do you want to retirement?(Y/N)");
                  input=input.toUpperCase();
                  if(input.equals("N"))
                  break;
                  else if(input.equals("Y"))
                  {
                   System.out.println(year+"year later you retire and your balance is "+formatter.format(balance));
                   System.exit(0);
                  }
                  else continue;
                 }
               while(input.equals("Y"));
              }
           }
              while(input.equals("N"));
       }
    }
      

  8.   

    倒数第二个 while(input.equals("Y"));程序根本不会运行到这里,这样写是不是有问题?能不能换个方式?
      

  9.   

    continue、break;的用法请查“Think in Java”
      

  10.   

    while(TURE)意思是总是运行,
    除非输入“N”