【一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义】
**开源地址:https://docs.qq.com/doc/DSmxTbFJ1cmN1R2dB **
System.out.println("The area of the hexagon is "+a);
}
}
================================================================
import java.util.Scanner;
public class disizhang {
public static void main(String[] args){
final double PI = 3.141592654;
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of sides: ");
int n = input.nextInt();
System.out.print("Enter the side: ");
double s = input.nextDouble();
double a = nss/(4*Math.tan(PI/n));
System.out.println("The area of the polygon is "+a);
}
}
================================================================
public class disizhang {
public static void main(String[] args){
final double PI = 3.141592654;
double alpha1 = Math.random()2PI;
double alpha2 = Math.random()2PI;
double alpha3 = Math.random()2PI;
double x1 = 40*Math.cos(alpha1);
double y1 = 40*Math.sin(alpha1);
double x2 = 40*Math.cos(alpha2);
double y2 = 40*Math.sin(alpha2);
double x3 = 40*Math.cos(alpha3);
double y3 = 40*Math.sin(alpha3);
double a = Math.sqrt((x1-x2)(x1-x2)+(y1-y2)(y1-y2));
double b = Math.sqrt((x2-x3)(x2-x3)+(y2-y3)(y2-y3));
double c = Math.sqrt((x1-x3)(x1-x3)+(y1-y3)(y1-y3));
double aa = Math.toDegrees(Math.acos((aa-bb-cc)/(-2b*c)));
double ab = Math.toDegrees(Math.acos((bb-aa-cc)/(-2a*c)));
double ac = Math.toDegrees(Math.acos((cc-bb-aa)/(-2a*b)));
System.out.println("The three angles are: “+aa+” “+ab+” "+ac);
}
}
================================================================
import java.util.Scanner;
public class disizhang {
public static void main(String[] args){
final double PI = 3.141592654;
Scanner input = new Scanner(System.in);
System.out.print("Enter the radius of the bounding circle: ");
double r = input.nextDouble();
double base = 0.1*PI;
System.out.println(“The coordinates of fibe points on the pentagon are”);
for(int i=0;i<5;i++)
{
System.out.printf(“(%.2f, %.2f)%n”,rMath.cos(base),rMath.sin(base));
base+=0.4*PI;
}
}
}
================================================================
import java.util.Scanner;
public class disizhang {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Ent6er an ASCII code: ");
int num = input.nextInt();
char str = (char)num;
System.out.printf(“The character for ASCII code %d is %c”,num,str);
}
}
================================================================
import java.util.Scanner;
public class disizhang {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter a character: ");
String jb = input.nextLine();
char str = jb.charAt(0);
int str2 = (int)str;
System.out.printf(“The Unicode for the character %c is %d”,str,str2);
}
}
=================================================================
public class disizhang {
public static void main(String[] args)
{
//在原来代码中进行修改
int answer = input.nextInt()修改为:char answer = input.nextLine().charAt(0)
if(answer1)—>if(answer’Y’)
}
}
=================================================================
import java.util.Scanner;
public class disizhang {
public static void main(String[] args){
System.out.print("Enter a decimal value (0 to 15): ");
Scanner input = new Scanner(System.in);
int num = input.nextInt();
if(num>=0&&num<=15){
if(num<10)
System.out.printf(“The hex value is %d”,num);
else
System.out.printf(“The hex value is %c”,‘A’+num-10);
}else
System.out.printf(“%d is an invalid input”,num);
}
}
=================================================================
import java.util.Scanner;
public class disizhang {
public static void main(String[] args){
String[] bins = {“0”,“1”,“10”,“11”,“100”,“101”,“110”,“111”,“1000”,“1001”,“1010”,“1011”,“1100”,“1101”,“1110”,“1111”};
System.out.print("Enter a hex digit: ");
Scanner input = new Scanner(System.in);
char str = input.nextLine().charAt(0);
if(str>=‘0’&&str<=‘9’)
System.out.printf(“The binary value is %s\n”,bins[str-‘0’]);
else if(str>=‘A’&&str<=‘F’)
System.out.printf(“The binary value is %s\n”,bins[str-‘A’+10]);
else
System.out.printf(“%c is an invalid input\n”,str);