1. Berechne die Anzahl der Wochen und die verbleibende Anzahl der Tage nach der Anzahl der Grundlage (46) Tagen
class day
{
private int day;
public day()
{
day=0;
}
public day(int day)
{
this.day=day;
}
public void setDay(int day)
{
this.day=day;
}
public int getDay()
{
return this.day;
}
public int weak()
{
return day/7;
}
public int residueDay()
{
return 365-day;
}
}
public class theDay
{
public static void main(String args[])
{
day Day=new day(46);
System.out.println("天数"+Day.getDay()+"是第"+Day. weak()+"周,"+"剩余的天数是:"+Day.residueDay());
}
}
2. Der Radius des Kreises von bekannten Radius = 1,5, seine Größe suchen
import java.lang.Math;
public class area
{
public static void main(String args[])
{
double radius= 1.50;
System.out.println("圆的面积是"+Math.PI*radius*radius);
}
}
3. Bestimmen, ob die Benutzereingabe eine gerade Zahl
import
java.util.*;
public class T1 {
public static void main(String[] args)
{
Scanner
input=new Scanner(System.in);
int a=input.nextInt();
if(a%2==0)
{
System.out.println("输入数是偶数");
}
else
System.out.println("输入数是奇数");
input.close();
}
}
4. Die Realisierung der Rechnerfunktion gibt der Benutzer zwei Zahlen, und wenn der Benutzer
Drücken Sie die 1: Finden Sie zwei Zahlen und
2 gemäß: die Differenz zwischen zwei Zahlen bestimmt,
3 durch: Erhalten des Produkts aus zwei Zahlen
04.00: Finden Sie die Quotienten aus zwei Zahlen
Ansonsten finden wir zwei Zahlen
import
java.util.*;
class caslputer{
private double x;
private double y;
public caslputer(){
x=0.0;
y=0.0;
}
public caslputer(double x,double y){
this.x=x;
this.y=y;
}
public void operation(int z){
switch(z){
case 1: System.out.println(x+y);break;
case 2: System.out.println(x-y);break;
case 3: System.out.println(x*y);;break;
case 4: System.out.println(x/y);break;
default:
System.out.println(x%y);
}}}
public class T1 {
public static void main(String[] args) {
Scanner
input=new Scanner(System.in);
double a=input.nextDouble();
double b=input.nextDouble();
caslputer
x=new caslputer(a,b);
int c=input.nextInt();
x.operation(c);
input.close();
}
}
Die drei beliebige Anzahl von Ein- und Ausgabe in absteigender Reihenfolge
import java.util.*;
public class T1 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
double a=input.nextDouble();
double b=input.nextDouble();
double c=input.nextDouble();
if(a>b)
if(b>c)
System.out.println(a+" " + b+" "+ c);
else
{
if(a>c)
System.out.println(a +" "+c+" " +b);
else
System.out.println(c+" " +b +" "+a);
}
else
if(a>c)
System.out.println(b+" " +a +" "+c);
else
{
if(b>c)
System.out.println(b+" " +c+" " +a);
else
System.out.println(c+" " +b +" "+a);
}
input.close();
}
}
6. Die Ausgabe von einer beliebigen Anzahl von fünf, wird die Anzahl der Wiederholungen bestimmt, ob oder in
import java.util.*;
public class T1 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
double a=input.nextDouble();
double b=input.nextDouble();
double c=input.nextDouble();
double d=input.nextDouble();
double e=input.nextDouble();
int n=0;
for(int i=0;i<2;i++)
{
if((a==b)||(a==c)||(a==d)||(a==e))
break;
else if((b==c)||(b==d)||(b==e))
break;
else if((c==d)||(c==e))
break;
else if(d==e)
break;
n=1;
}
if(n==1)
System.out.println("无重复数据");
else
System.out.println("有重复数据");
input.close();
}
}
7. Mit if ... else if-Anweisung Schaltjahr Problem zu bestimmen
import java.util.*;
public class T1 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int year=input.nextInt();
if ((year % 400 == 0) || ((year % 100 == 0)
&& (year % 4 == 0)))
System.out.println("这年是闰年!!!");
else
System.out.println("不是闰年!!!");
input.close();
}
}
8. fragte ein Datum repräsentativ für die 8-Bit-Integer eingeben, die am folgenden Tag 1 Tag berechnet wird und was Datum
import java.text.DateFormat;
import java.util.*;
public class T1 {
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int a=input.nextInt();
int year;
int month;
int day;
year=a/10000;
month=a/100%100;
day=a%100;
Calendar calendar=Calendar.getInstance();
calendar.clear();
calendar.set(year, month-1, day-1);
DateFormat t=DateFormat.getDateInstance(DateFormat.LONG);
System.out.println("上一天"+t.format(calendar.getTime()));
calendar.set(year, month-1, day+1);
System.out.println("下一天"+t.format(calendar.getTime()));
input.close();
}
}