十一作业
Posted 打得不错
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了十一作业相关的知识,希望对你有一定的参考价值。
1.
class A
{
public static void main(String[] args)
{
System.out.println("5+5="+5+5);
}
}
2.
class B
{
public static void main(String[] args)
{
int a=3,b;
b=a++;
System.out.println("a="+a+",b="+b);
}
}
3.
class C
{
public static void main(String[] args)
{
short s=3;
s=s+4;
System.out.println("s="+s);
}
}
class C2
{
public static void main(String[] args)
{
short s=3;
s+=4;
System.out.println("s="+s);
}
}
4.
class D
{
public static void main(String[] args)
{
System.out.println(6&3);
System.out.println(6|3);
System.out.println(6^3);
System.out.println(3<<2);
System.out.println(3>>1);
}
}
5.
class E1
{
public static void main(String[] args)
{
int x=0,y;
y=x>1?100:200;
System.out.println("y="+y);
}
}
import java.util.Scanner;
class E2
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int x,y;
System.out.println("Enter the x ");
x=input.nextInt();
System.out.println("Enter the y ");
y=input.nextInt();
y=x>y?x:y;
System.out.println("The larger of the two numbers is"+y);
}
}
import java.util.Scanner;
class E3
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int x,y,z;
System.out.println("Enter the x ");
x=input.nextInt();
System.out.println("Enter the y ");
y=input.nextInt();
System.out.println("Enter the z ");
z=input.nextInt();
y=x>y?x:y;
z=y>z?y:z;
System.out.println("The largest of the three numbers is"+ z);
}
}
6.
import java.util.Scanner;
class F
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int month;
System.out.println("Enter the month ");
month=input.nextInt();
if(month>=3&&month<=5){
System.out.println("This month is spring");
}else if(month>=6&&month<=8){
System.out.println("This month is summer");
}else if(month>=9&&month<=11){
System.out.println("This month is autumn");
}else if(month==12){
System.out.println("This month is winter");
}else if(month>=1&&month<=2){
System.out.println("This month is winter");
}else{
System.out.println("Error!");
}
}
}
7.
import java.util.Scanner;
class G
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int month;
System.out.println("Enter the month ");
month=input.nextInt();
switch (month)
{
case 1: case 2: case 12:
System.out.println("This month is winter");
break;
case 3: case 4: case 5:
System.out.println("This month is spring");
break;
case 6: case 7: case 8:
System.out.println("This month is summer");
break;
case 9: case 10: case 11:
System.out.println("This month is autumn");
break;
default:
System.out.println("Error!");
break;
}
}
}
8.
class H1
{
public static void main(String[] args)
{
int x=1;
do{
System.out.println("x="+x);
x++;
}while(x<1);
}
}
class H2
{
public static void main(String[] args)
{
int y=1;
while(y<1){
System.out.println("y="+y);
y++;
}
}
}
9.
class J1
{
public static void main(String[] args)
{
for(int x=1;x<3;x++)
{
System.out.println("x="+x);
}
}
}
class J2
{
public static void main(String[] args)
{
int x=1;
for(System.out.println("a");x<3;System.out.println("c"))
{
System.out.println("d");
x++;
}
}
}
以上是关于十一作业的主要内容,如果未能解决你的问题,请参考以下文章