import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
*/
/**
* @author Home
*
*/
public class student
{
/**
* @param args
*/
String average(float sub1,float sub2,float sub3)
{
float average = (sub1+sub2+sub3)/3;
if( average > 50)
return "PASS";
else
return "FAIL";
}
String addName(String name)
{
return name;
}
public static void main(String[] args) throws NumberFormatException, IOException
{
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
student stu = new student();
int loop_option = 0;
do
{
System.out.println("--------------STUDENT DETAILS---------------");
System.out.println("Choose the operation from the following options.");
System.out.println(" 1.ADDNAME");
System.out.println(" 2.AVERAGE_RESULT");
System.out.println(" 3.EXIT");
System.out.println("CHOOSE THE OPERATION U WANT:");
int option = Integer.parseInt(br.readLine());
switch(option)
{
case 1:
System.out.println("Enter the name");
String name = br.readLine();
System.out.println("The Inserted student name is " +stu.addName(name));
break;
case 2:
outsideloops:
System.out.println("Enter the marks (in 100):");
System.out.println("Subject 1:");
float sub1 = Float.parseFloat(br.readLine());
if (sub1 >= 101)
goto outsideloops;
System.out.println("Subject 2:");
float sub2=Float.parseFloat(br.readLine());
System.out.println("Subject 3:");
float sub3=Float.parseFloat(br.readLine());
System.out.println("The Student is "+stu.average(sub1,sub2,sub3)+ "in the examinations");
break;
case 3:
System.exit(0);
default:
System.out.println("Please choose the valid option");
//break;
}
System.out.println("if U want 2 use further press 1 to continue...");
loop_option=Integer.parseInt(br.readLine());
}
while (loop_option == 1);
System.out.println("The STUDENT program is terminating now.");
}
}
case 2:
float sub1 = 0.0;
do {
System.out.println("Enter the marks (in 100):");
System.out.println("Subject 1:");
sub1 = Float.parseFloat(br.readLne());
} while (sub1 >= 101);
... rest of the code ...
请注意,此代码等效于这种特殊情况。没有通用的替代品goto;如果有的话,他们只会call it goto并完成它。每个案例都会有所不同,更换完全取决于goto会被使用。