else
System.out.println(“Invalid input.”);
}
}
=================================================================
import java.util.Scanner;
public class disanzhang {
public static void main(String[] args){
int[] mdays = {31,28,31,30,31,30,31,31,30,31,30,31};
Scanner input = new Scanner(System.in);
System.out.print(“Enter year: (e,g.,2012):”);
int year = input.nextInt();
System.out.print("Enter month: 1-12: ");
int month = input.nextInt();
if((year%40&&year%100!=0)||(year%4000))
mdays[1]=29;
System.out.print(“Enter the day of the month: 1-”+mdays[month-1]+": ");
int q = input.nextInt();
if(month1||month2){
month+=12;
year–;
}
int h=(q+26*(month+1)/10+year%100+year%100/4+year/100/4+5*(year/100))%7;
String[] days = {“Sat”,“Sun”,“Mon”,“Tue”,“Wed”,“Thu”,“Fri”};
System.out.println("Day of the week is "+days[h]);
}
}
=================================================================
import java.util.Scanner;
public class disanzhang {
public static void main(String[] args){
System.out.print("Enter a point with two coordinates: ");
Scanner input = new Scanner(System.in);
double x = input.nextDouble();
double y = input.nextDouble();
if(xx+yy>100)
System.out.println(“Point (”+x+“, “+y+”) is not in the circle”);
else
System.out.println(“Point (”+x+“, “+y+”) is in the circle”);
}
}
=================================================================
import java.util.Scanner;
public class disanzhang {
public static void main(String[] args){
System.out.print("Enter a point with two coordinates: ");
Scanner input = new Scanner(System.in);
double x = input.nextDouble();
double y = input.nextDouble();
if(x<=10/2&&x>=-10/2&&y<=5.0/2&&y>=-5.0/2)
System.out.println(“Point (”+x+“, “+y+”) is in the rectangle”);
else
System.out.println(“Point (”+x+“, “+y+”) is not in the rectangle”);
}
}
=================================================================
public class disanzhang {
public static void main(String[] args){
int num = (int)(Math.random()*13);
int dick = (int)(Math.random()*4);
String[] nums = {“Ace”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”,“Jack”,“Queen”,“King”};
String[] dicks = {“Clubs”,“Diamonds”,“Hearts”,“Spades”};
System.out.println("The card you picked is “+nums[num]+” of "+dicks[dick]);
}
}
=================================================================
import java.util.Scanner;
public class disanzhang {
public static void main(String[] args){
System.out.print("Enter x1, y1, x2, y2, x3, y3, x4, y4: ");
Scanner input = new Scanner(System.in);
double x1 = input.nextDouble();
double y1 = input.nextDouble();
double x2 = input.nextDouble();
double y2 = input.nextDouble();
double x3 = input.nextDouble();
double y3 = input.nextDouble();
double x4 = input.nextDouble();
double y4 = input.nextDouble();
double a = y1-y2;
double b = x2-x1;
double c = y3-y4;
double d = x4-x3;
double e = (y1-y2)*x1-(x1-x2)*y1;
double f = (y3-y4)*x3-(x3-x4)*y3;
double jb = ad-bc;
if(jb==0)
System.out.println(“The two lines are parallel”);
else
System.out.println(“The intersecting point is at (”+(ed-bf)/jb+“, “+(af-ec)/jb+”)”);
}
}
=================================================================
import java.util.Scanner;
public class disanzhang {
public static void main(String[] args){
System.out.print("Enter an integer: ");
Scanner input = new Scanner(System.in);
int n = input.nextInt();
System.out.println("Is “+n+” divisible by 5 and 6? "+(n%50&&n%60));
System.out.println("Is “+n+” divisible by 5 or 6? "+(n%50||n%60));
System.out.println("Is “+n+” divisible by 5 or 6, but not both? "+(n%50^n%60));
}
}
=================================================================
import java.util.Scanner;
public class disanzhang {
public static void main(String[] args){
System.out.print("Enter a point’s x- and y- coordinates: ");
Scanner input = new Scanner(System.in);
double x = input.nextDouble();
double y = input.nextDouble();
if(x>=0&&x<=200&&y>=0&&y<=100-0.5*x)
System.out.println(“The point is in the triangle”);
else
System.out.println(“The point is not in the triangle”);
}
}
=================================================================
import java.util.Scanner;
public class disanzhang {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter r1’s center x-, y-coordinates, width, and height: ");
double x1 = input.nextDouble();
double y1 = input.nextDouble();
double w1 = input.nextDouble();
double h1 = input.nextDouble();
System.out.print("Enter r2’s center x-, y0coordinates, width, and height: ");
double x2 = input.nextDouble();
double y2 = input.nextDouble();
double w2 = input.nextDouble();
double h2 = input.nextDouble();
if((x1+w1/2>=x2+w2/2)&&(x1-w1/2<=x2-w2/2)&&(y1+h1/2>=y2+h2/2)&&(y1-h1/2<=y2-h2/2))
System.out.println(“r2 is inside r1”);
else if((x2-w2/2>x1+w1/2)||(x2+w2/2<x1-w1/2)||(y2-h2/2>y1+h1/2)||(y2+h2/2<y1-h1/2))
System.out.println(“r2 does not overlap r1”);
else if((x2+w2/2>=x1+w1/2)&&(x2-w2/2<=x1-w1/2)&&(y2+h2/2>=y1+h1/2)&&(y2-h2/2<=y1-h1/2))
System.out.println(“r1 is inside r2”);
else
System.out.println(“r2 overlaps r1”);
}
}
=================================================================
import java.util.Scanner;
public class disanzhang {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter circle’s center x-, y-coordinates, and radius: ");
double x1 = input.nextDouble();
double y1 = input.nextDouble();
double r1 = input.nextDouble();
System.out.print("Enter circle2’s center x-, y-coordinates, and radius: ");
double x2 = input.nextDouble();
double y2 = input.nextDouble();
double r2 = input.nextDouble();
if(Math.pow((x1-x2)(x1-x2)+(y1-y2)(y1-y2),0.5)<=Math.abs(r1-r2))
System.out.println(“circle2 is inside circle1”);
else if(Math.pow((x1-x2)(x1-x2)+(y1-y2)(y1-y2),0.5)<=r1+r2)
System.out.println(“circle2 overlaps circle1”);
else
System.out.println(“circle2 does not overlap circle1”);
}
}
=================================================================
import java.util.Scanner;
public class disanzhang {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print(“Enter the time zone offset to GMT:”);