}
public int getR() { }
return r;
JavaSE初级—第六单元:循环结构
1:实现双色球的彩票功能。规则:从36个红球中随机选择不重复的6个数,从15个篮球中随机选择1个组成一注彩票。可以选择买多注。
import java.util.Arrays; public class Ticket {
public static void main(String[] args) {
int []a =new int[7];
a[0]=(int)(36*Math.random()+1); int t;
for (int i = 1; i < 6; i++) {
t=(int)(6*Math.random()+1); for(int j=0;j
if(t==a[j]){
i--; break;
}else{
} }
}
}
}
a[i]=t;
a[6]=(int)(36*Math.random()+1); System.out.println(Arrays.toString(a));
2:输出1-100之间的不能被5整除的数,每5个一行。
public class Number{
public static void main(String[] args){
int t=0;
for (int i = 1; i <= 100; i++) { }
if(i%5!=0){ }
System.out.print(i+\t++; if(t%5==0){ }
System.out.println();
} }
JavaSE初级—第七单元 面向对象的基本概念 1:写一个人的类 属性:名字,性别,年龄
方法:(1)自我介绍的方法(2)吃饭的方法 创建一个对象“张三” public class Person{
String name=\张三\char sex='男'; int age=21;
public static void main(String[]args){ }
public void introduceMySelf(){
Person 张三 = new Person(); 张三.introduceMySelf(); 张三.eat();
System.out.println(\大家好,我叫\,性别\,今年\岁\
}
public void eat(){
System.out.println(\用筷子吃饭\
}
}
2:写一个汽车类:
属性:品牌;车长;颜色;价格; 方法:跑的方法
创建五个对象:“捷达”,“宝马”,“劳斯莱斯”,“科鲁兹”,“迈锐宝” public class Car{
public static void main(String[]args){
Message jieDa=new Message(\捷达\黑色\
Message baoMa=new Message(\宝马\白色\
Message laoSi=new Message(\劳斯莱斯\\棕色\
Message keLu=new Message(\科鲁兹\白色\
Message maiKe=new Message(\迈锐宝\雪白色\
}
public static void runWay(){
System.out.println(\捷达横着跑\runWay();
}
}
System.out.println(\宝马直线跑\System.out.println(\劳斯莱斯转弯跑\System.out.println(\科鲁兹上坡跑\System.out.println(\迈锐宝飞速跑\
class Message{
private String brand; private double length; private String color; private double price;
public Message(String brand, double length, String color, double price) {
this.brand = brand; this.length = length; this.color = color;
this.price = price;//品牌;车长;颜色;价
格;
System.out.println(\品牌:\车长:\颜色:\价格:\ }
}