1:
public class Test1 {
public static void main(String[] args){
int n=5;
for(int i=0; i
System.out.print("#");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
}
2:
public class Test2 {
public static void main(String[] args){
int total=50;
int n=0;
int j=0;
for(int i=total; i>0; i--){
if(j==2){
j=0;
i++;
}else{
j++;
}
n++;
}
System.out.println("共喝了"+n+"瓶");
}
}
3:
public class Test3 {
public static void main(String[] args){
int[] arr = new int[50];
int j=0;
for(int i=0; i<50; i++){
int n = (int) (Math.random()*300);
System.out.println(n);
if(n%2==0){
arr[j++]=n;
}
}
System.out.println("偶数:");
for(int i=0; i
System.out.println(arr[i]);
}
}
}
}
4:
public class Test4 {
public static void main(String[] args){
Vehicle v0 = new Vehicle();
v0.print();
Vehicle v1 = new Car();
v1.print();
Vehicle v2 = new Truck();
v2.print();
}
}
class Vehicle{
public Vehicle(){
}
int wheels;
int weight;
public void print(){
System.out.println("这是Vehicle");
}
}
class Car extends Vehicle{
public Car(){
super();
}
int loader;
public void print(){
System.out.println("这是Car");
}
}
class Truck extends Car{
public Truck(){
super();
}
int payload;
public void print(){
System.out.println("这是Truck");
}
}
太简单了都是些基本算法``不会的话``你就最好别学了 浪费钱
痛楼上看法一致。
何况一题才5分。。
这点你小气了。
自己想想挺简单
1:
public
class
Test1
{
public
static
void
main(String[]
args){
int
n=5;
for(int
i=0;
i
for(int
j=0;
j
if(j==0
||
j==n-1||i==0||i==n-1){
System.out.print("#");
}else{
System.out.print("
");
}
}
System.out.println();
}
}
}
2:
public
class
Test2
{
public
static
void
main(String[]
args){
int
total=50;
int
n=0;
int
j=0;
for(int
i=total;
i>0;
i--){
if(j==2){
j=0;
i++;
}else{
j++;
}
n++;
}
System.out.println("共喝了"+n+"瓶");
}
}
3:
public
class
Test3
{
public
static
void
main(String[]
args){
int[]
arr
=
new
int[50];
int
j=0;
for(int
i=0;
i<50;
i++){
int
n
=
(int)
(Math.random()*300);
System.out.println(n);
if(n%2==0){
arr[j++]=n;
}
}
System.out.println("偶数:");
for(int
i=0;
i
if(arr[i]!=0){
System.out.println(arr[i]);
}
}
}
}
4:
public
class
Test4
{
public
static
void
main(String[]
args){
Vehicle
v0
=
new
Vehicle();
v0.print();
Vehicle
v1
=
new
Car();
v1.print();
Vehicle
v2
=
new
Truck();
v2.print();
}
}
class
Vehicle{
public
Vehicle(){
}
int
wheels;
int
weight;
public
void
print(){
System.out.println("这是Vehicle");
}
}
class
Car
extends
Vehicle{
public
Car(){
super();
}
int
loader;
public
void
print(){
System.out.println("这是Car");
}
}
class
Truck
extends
Car{
public
Truck(){
super();
}
int
payload;
public
void
print(){
System.out.println("这是Truck");
}
}