标签:
package exercise; import java.util.Scanner; public class Exe4_Ticket_type { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); System.out.println("请输入票总数"); int ticket = input.nextInt(); for(int i = 0 ; i < ticket ; i++){ System.out.println("请输入姓名:"); String name1 = input.next(); if(name1.equals("n")){ System.out.println("退出程序"); break; } System.out.println("请输入年龄:"); int age1 = input.nextInt(); Exe4_Ticket zhangsan = new Exe4_Ticket(); zhangsan.tic(name1,age1); } input.close(); } }
package exercise; public class Exe4_Ticket { String name; int age; /*public void nam(String name){ if(name.equals("n")){ System.out.println("退出程序"); return; } }*/ public void tic(String name, int age){ if(age <= 5 ){ System.out.println(name+"的年龄为:"+age+",门票免费"); } else{ System.out.println(name+"的年龄为:"+age+",门票价格为:20元"); } } //构造函数 /*public Exe4_Ticket(){ } public Exe4_Ticket(String name, int age){ this.name = name; this.age = age; }*/ }
标签:
原文地址:http://www.cnblogs.com/xiaolei121/p/5731518.html