首页 文章 代码练习

代码练习

2020-07-07 20:27  浏览数:2426  来源:小键人234821    

public class JavaDay001_1 {
public static void main(String[] args) {
System.out.println(args);
}
}
public class JavaDay001_2 {
public static void main(String[] args) {
System.out.println("128 & 129 = " + (128 & 129));
System.out.println("56 | 32 = " + (56 | 32));
System.out.println("27 ^ 123 = " + (27 ^ 123));
}
}
import java.util.Scanner;
public class JavaDay001_3 {
public static void main(String[] args) {
System.out.println("请输入3个数:");
Scanner scanner = new Scanner(System.in);
int nNumA = scanner.nextInt();
int nNumB = scanner.nextInt();
int nNumC = scanner.nextInt();
int nMax = 0;
if (nNumA >= nNumB && nNumA >= nNumC)
{
nMax = nNumA;
}
else if (nNumB >= nNumC && nNumB >= nNumA)
{
nMax = nNumB;
}
else if (nNumC >= nNumA && nNumC >= nNumB)
{
nMax = nNumC;
}
else
{
System.out.println("无法比较!");
}
System.out.println("Max = " + nMax);
}
}
import com.sun.webkit.BackForwardList;
import java.util.Scanner;
public class JavaDay001_4 {
public static void main(String[] args) {
System.out.println("请输入年:");
Scanner scanner = new Scanner(System.in);
int nYear = scanner.nextInt();
System.out.println("请输入月:");
int nMounth = scanner.nextInt();
int nflag = 0;
if (nYear % 4 == 0)
{
if (nYear % 100 == 0)
{
if (nYear % 400 == 0)
{
nflag = 1;
System.out.println(nYear + "年是润年");
}
else
{
System.out.println(nYear + "年不是润年");
}
}
else
{
nflag = 1;
System.out.println(nYear + "年不是润年");
}
}
else
{
System.out.println(nYear + "年不是润年");
}
//判断2016年月份的天数
if (nMounth == 1
|| nMounth == 3
|| nMounth == 5
|| nMounth == 7
|| nMounth == 8
|| nMounth == 10
|| nMounth == 12 )
{
System.out.println(nYear + "年" + nMounth + "月份的天数是:31" );
}
else if (nMounth == 4
|| nMounth == 6
|| nMounth == 9
|| nMounth == 11)
{
System.out.println(nYear + "年" + nMounth + "月份的天数是:30" );
}
else
{
if (nflag == 0)
{
System.out.println(nYear + "年" + nMounth + "月份的天数是:28" );
}
else
{
System.out.println(nYear + "年" + nMounth + "月份的天数是:29" );
}
}
}
}
import java.util.Scanner;
public class JavaDay001_5 {
public static void main(String [] args)
{
System.out.println("请输入学生学号:");
Scanner scanner = new Scanner(System.in);
int nStudent = scanner.nextInt();
int nStudentYear = nStudent / 10000;
int nStudentTime = (nStudent / 100) % nStudentYear;
int nStudentId = nStudent % (nStudent / 100);
System.out.println("学生学号:" + nStudent);
System.out.println("学生入学年份:" + nStudentYear + "年");
System.out.println("学生期数:" + nStudentTime + "期");
System.out.println("学生序号:" + nStudentId + "号");
}
}
import java.util.Scanner;
public class JavaDay001_6 {
public static void main(String [] args)
{
System.out.println("请指定分数:");
Scanner scanner = new Scanner(System.in);
int score = scanner.nextInt();
int nCount = 0;
if (score < 60)
{
int temp = score;
while (temp < 60)
{
temp++;
nCount++;
}
System.out.println("加分前成绩:" + score);
System.out.println("加分后成绩:" + temp);
System.out.println("共加了" + nCount + "次!");
}
else
{
System.out.println("不用加分!");
}
}
}
public class JavaDay001_7 {
public static void main(String [] args){
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 7; j++)
{
if (i == 0 && j == 3)
{
System.out.print("*");
}
else if(i == 1 && j < 5 && j > 1)
{
System.out.print("*");
}
else if(i == 2 && j < 6 && j > 0)
{
System.out.print("*");
}
else if (i == 3)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 7; j++)
{
if(i == 0 && j < 6 && j > 0)
{
System.out.print("*");
}
else if (i == 1 && j < 5 && j > 1)
{
System.out.print("*");
}
else if (i == 2 && j ==3)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
}
}
import java.util.BitSet;
import java.util.Scanner;
public class JavaDay001_8 {
public static void main(String []args)
{
System.out.println("请输入五位数会员卡号:");
Scanner scanner = new Scanner(System.in);
int nVIPCard = scanner.nextInt();
int nW = nVIPCard / 10000;
int nQ = (nVIPCard / 1000) % 10;
int nB = (nVIPCard / 100) % 10;
int nS = (nVIPCard / 10) % 10;
int nG = nVIPCard % 10;
System.out.println("会员卡号:" + nVIPCard);
System.out.println("万位数:" + nW
+ " 千位数:" + nQ
+ " 百位数:" + nB
+ " 十位数:" + nS
+ " 个位数:" + nG);
System.out.println("会员卡号" + nVIPCard
+ "每位的总和为:"
+ (nW + nQ + nB + nS + nG));
}
}
import java.util.Scanner;
public class JavaDay001_9 {
static String CaculateWeekDay(int y,int m,int d)
{
if(m==1)
{
m = 13;
y--;
}
if(m==2)
{
m=14;
y--;
}
int week=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
String weekstr = null;
switch(week)
{
case 0: weekstr="星期一"; break;
case 1: weekstr="星期二"; break;
case 2: weekstr="星期三"; break;
case 3: weekstr="星期四"; break;
case 4: weekstr="星期五"; break;
case 5: weekstr="星期六"; break;
case 6: weekstr="星期日"; break;
}
return weekstr;
}
public static void main(String [] args)
{
int [][] day = new int[5][7];
System.out.print("请选择年份:");
Scanner scanner = new Scanner(System.in);
int nYear = scanner.nextInt();
System.out.print("请选择月份:");
int nMounth = scanner.nextInt();
System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");
int bflag = 0;
String strWeek = CaculateWeekDay(nYear, nMounth, 1);
if (strWeek.equals("星期一"))
{
day[0][1] = 1;
}
if (strWeek.equals("星期二"))
{
day[0][2] = 1;
}
if (strWeek.equals("星期三"))
{
day[0][3] = 1;
}
if (strWeek.equals("星期四"))
{
day[0][4] = 1;
}
if (strWeek.equals("星期五"))
{
day[0][5] = 1;
}
if (strWeek.equals("星期六"))
{
day[0][6] = 1;
bflag = 1;
}
if (strWeek.equals("星期日"))
{
day[0][0] = 1;
}
if (nMounth == 1 ||
nMounth == 3 ||
nMounth == 5 ||
nMounth == 7 ||
nMounth == 8 ||
nMounth == 10 ||
nMounth == 12)
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 7; j++)
{
if (day[i][j] == 1)
{
for (int m = 0; m < 31; m++)
{
System.out.print(day[i][j] + m + "\t\t");
if ((j + m + 1) % 7 == 0)
{
System.out.println();
}
}
}
else
{
System.out.print("\t\t");
}
}
}
}
else if (nMounth == 4 ||
nMounth == 6 ||
nMounth == 9 ||
nMounth == 11)
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 7; j++)
{
if (day[i][j] == 1)
{
for (int m = 0; m < 30; m++)
{
System.out.print(day[i][j] + m + "\t\t");
if ((j + m + 1) % 7 == 0)
{
System.out.println();
}
}
}
else
{
System.out.print("\t\t");
}
}
}
}
else
{
if ((nYear % 4 == 0 || nYear % 400 == 0) && nYear % 100 != 0)
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 7; j++)
{
if (day[i][j] == 1)
{
for (int m = 0; m < 29; m++)
{
System.out.print(day[i][j] + m + "\t\t");
if ((j + m + 1) % 7 == 0)
{
System.out.println();
}
}
}
else
{
System.out.print("\t\t");
}
}
}
}
else
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 7; j++)
{
if (day[i][j] == 1)
{
for (int m = 0; m < 28; m++)
{
System.out.print(day[i][j] + m + "\t\t");
if ((j + m + 1) % 7 == 0)
{
System.out.println();
}
}
}
else
{
System.out.print("\t\t");
}
}
}
}
}
}
}



声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)