java
Posted xuejye
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java相关的知识,希望对你有一定的参考价值。
//机器人
package org.lanqiao.test;
import java.util.*;
public class test
public static void main (String args[])
Scanner cin = new Scanner (System.in);
Random rand=new Random();
while(true)
int s=cin.nextInt();
int AI=rand.nextInt(3);
System.out.println("AI的结果是:"+(AI==0?"剪刀":AI==1?"石头":AI==2?"布":""));
if(0<=s&&s<=2)
if(s==AI)
System.out.println("平局");
else if((s+1)%3==AI)
System.out.println("失败");
else
System.out.println("获胜");
else if(s==99)
break;
else
System.out.println("输入错误");
//6.(i-1)*m+1 -- i*m
//9.
package org.lanqiao.test;
import java.util.*;
public class test
public static void main (String args[])
Scanner cin=new Scanner (System.in);
int s=cin.nextInt();
if(s%4==0&&s%100!=0)
System.out.println("闰年");
else
if(s%400==0)
System.out.println("闰年");
else
System.out.println("平年");
package org.lanqiao.test;
import java.util.*;
public class test
public static void main (String args[])
Scanner cin=new Scanner (System.in);
int s=cin.nextInt();
if(s%4==0&&s%100!=0)
System.out.println("闰年");
else
if(s%400==0)
System.out.println("闰年");
else
System.out.println("平年");
//10.
package org.lanqiao.test;
import java.util.*;
public class test
public static void main (String args[])
Scanner cin=new Scanner (System.in);
double a=cin.nextDouble();
double s=a-3500-262;
double sum=0;
if(0<=s&&s<=1500)
sum=s*0.03-0;
else if(s<=4500)
sum=s*0.1-105;
else if(s<=9000)
sum=s*0.2-555;
else if(s<=35000)
sum=s*0.25-1005;
else if(s<= 55000)
sum=s*0.3-2755;
else if(s<=80000)
sum=s*0.35-5505;
else
sum=s*0.45-13505;
a-=sum+262;
System.out.println(a);
//6.
package org.lanqiao.test;
import java.util.*;
public class test
public static void main (String args[])
for(int i=0;i<100;i++)
for(int j=0;j<100;j++)
if(((100-2*i-3*j)*3+i+j)==100)
System.out.printf("%d %d %d\\n",i,j,(100-2*i-3*j)*3);
//9.
package org.lanqiao.test;
import java.util.*;
public class test
public static void main (String args[])
Scanner cin =new Scanner(System.in);
int n=cin.nextInt();
for(int i=1;i<=n;i++)
for(int j=n-i;j>0;j--)
System.out.print(" ");
for(int j=0;j<i;j++)
System.out.print("*");
for(int j=0;j<i-1;j++)
System.out.print("*");
System.out.println();
//10.
package org.lanqiao.test;
import java.util.*;
public class test
public static void main (String args[])
for(int i=1;i<=9;i++)
for(int j=1;j<=i;j++)
System.out.printf("%d * %d = %d ",i,j,i*j);
System.out.println("");
//竖版
package org.lanqiao.test;
import java.util.*;
public class test
public static void main (String args[])
char [][] arr = new char[3][];
arr[0]= new char[] '老','夫','聊','发','少','年','狂';
arr[1]= new char[] '左','牵','黄';
arr[2]= new char[] '右','擎','苍';
int maxx=0;
for(int i=0;i<arr.length;i++)
maxx=maxx>=arr[i].length?maxx:arr[i].length;
for(int i=0;i<maxx;i++)
for(int j=0;j<arr.length;j++)
if(i<=arr[j].length)
System.out.printf("%c ",arr[j][i]);
System.out.println("");
//对角线和
package org.lanqiao.test;
import java.util.*;
public class test
public static void main (String args[])
char [][] arr =new char [3][];
arr[0]=new char[] 1,2,3;
arr[1]=new char[] 4,5,6;
arr[2]=new char[] 7,8,9;
int sum=0;
for(int i=0;i<3;i++)
sum+=arr[i][i];
System.out.println(sum);
sum=0;s
for(int i=0;i<3;i++)
sum+=arr[i][2-i];
System.out.println(sum);
//PDF10 13 14
//PDF11 10 11
//PDF8 全写
package org.lanqiao.test;
import java.util.*;
public class test
public static void main (String args[])
Map<Integer ,String > mmap = new HashMap<Integer ,String>();
mmap.put(2006,"意大利");
mmap.put(2002,"巴西");
mmap.put(1998,"法国");
mmap.put(1994,"巴西");
mmap.put(1990,"德国");
mmap.put(1986,"阿根廷");
mmap.put(1982,"意大利");
mmap.put(1978,"阿根廷");
mmap.put(1974,"德国");
mmap.put(1970,"巴西");
mmap.put(1966,"英格兰");
mmap.put(1962,"巴西");
mmap.put(1958,"巴西");
mmap.put(1954,"德国");
mmap.put(1950,"乌拉圭");
mmap.put(1938,"意大利");
mmap.put(1934,"意大利");
mmap.put(1930,"乌拉圭");
Scanner cin = new Scanner(System.in);
// int n=cin.nextInt();
// System.out.println(mmap.get(n));
String s=cin.next();
Iterator<Integer> it=mmap.keySet().iterator();
int flag=0;
while(it.hasNext())
int next = it.next().intValue();
if(s.equals(mmap.get(next)))
System.out.println(next);
flag=1;
if(flag==0)
System.out.println("没有此国家");
package org.lanqiao.test;
import java.util.*;
public class test
public static void main (String args[])
Map< Character ,Integer > mmap = new HashMap<Character ,Integer>();
Scanner cin = new Scanner(System.in);
String s=cin.next();
for(int i = 0 ; i < s.length() ; i++)
Character mid = s.charAt(i);
if(mmap.get(s.charAt(i))==null)
mmap.put(mid,1);
else
Integer midnum=mmap.get(mid);
midnum+=1;
mmap.put(mid, midnum);
Iterator<Character> it=mmap.keySet().iterator();
while(it.hasNext())
Character next=it.next();
System.out.println(next+" "+mmap.get(next).toString());
11.10:100 100
11:
ma1
ma2 0
In Finally
ma1
In Finally
package org.lanqiao.test;
import java.util.*;
interface IA
void m1();
int a = 100;
class MyClass implements IA
public void m1()
pdf8
1.
public class test
static Scanner cin = new Scanner (System.in);
public static void main(String args[])
IA ia = new MyClass();
ia.m1();
System.out.println(IA.a);
2.
package org.lanqiao.test;
import java.util.*;
interface IA
void m1();
void m2();
abstract class test implements IA
public void m1()
class MyClassB extends test
public void m2()
3.
package org.lanqiao.test;
import java.util.*;
interface IA
void ma();
interface IB extends IA
void mb();
interface IC
void mc();
interface ID extends IB, IC
void md();
class ClassE implements ID
public void ma()
;
public void mb()
;
public void mc()
;
public void md()
;
public class test
public static void main(String args[])
IC ic = new ClassE();
//调用ma 方法
IA ia = (IA)ic;
ia.ma();
//调用mb 方法
IB ib = (IB)ic;
ib.mb();
//调用mc 方法
ic.mc();
//调用md 方法
ID id = (ID)ic;
id.md();
true
true
true
true
true
4.true
true
true
true
5.A E
6.Red Light shine in Red
Yellow Light shine in Yellow
Green Light shine in Green
7.
TeacherA teach Java
TeacherB teach Java
8.
as[0].eat();
as[1].eat();
as[2].eat();
Dog dog=(Dog)as[0];
dog.play();
Cat cat=(Cat)as[1];
cat.play();
9.略
10.
class MyService implements ServiceInterface
public void doService1()
public void doService2()
public void doService3()
class MyServices extends AbstractService
以上是关于java的主要内容,如果未能解决你的问题,请参考以下文章