JAVA 基础语法5

九九乘法表

import java.util.Scanner;

public class Main
{
	
    public static void main(String[] args) 
    {
         Scanner reader = new Scanner(System.in);
         while (reader.hasNext())
         {
        	 int n=reader.nextInt();
        	 for(int i=1;i<=n;i++)
        	 {
        		 for(int j=1;j<=i;j++)
        		 {
        			 System.out.printf("%d*%d=%d",j,i,j*i);
        			 if(j==i)
        			 {
        				 System.out.println();
        			 }
        			 else 
        			 {
        				 System.out.print(" ");
        			 }
        		 }
        	 }
         }
       reader.close();
    }
}


C语言实验——求绝对值(选择结构)
Time Limit: 1000 ms Memory Limit: 65536 KiB

import java.util.Scanner;

public class Main
{
	
    public static void main(String[] args) 
    {
         Scanner reader = new Scanner(System.in);
        int n=reader.nextInt();
        if(n>=0)
        {
        	System.out.println(n);
        }
        else
        {
        	System.out.println(-n);
        }
       reader.close();
    }
}


小鑫の日常系列故事(二)——石头剪子布

import java.util.Scanner;

public class Main
{
	
    public static void main(String[] args) 
    {
         Scanner reader = new Scanner(System.in);
         String A= "Rock";
         String B= "Scissors";
         String C= "Cloth";
         String D=reader.next();
         String E=reader.next();
         if((D.equals(A)&&E.equals(B))||(D.equals(B)&&E.equals(C))||((D.equals(C)&&E.equals(A))))
         {
        	 System.out.println("Win");
         }
         else if((D.equals(A)&&E.equals(A))||(D.equals(B)&&E.equals(B))||((D.equals(C)&&E.equals(C))))
         {
        	 System.out.println("Equal");
         }
         else
         {
        	 System.out.println("Lose");
         }
       reader.close();
    }
}


闰年

import java.util.Scanner;

public class Main
{
	
    public static void main(String[] args) 
    {
         Scanner reader = new Scanner(System.in);
        int year = reader.nextInt();
        if(year%4==0&&year%100!=0)
        {
        	System.out.println("Yes");
        }
        else if(year%4==0&&year%400==0)
        {
        	System.out.println("Yes");
        }
        else 
        {
        	System.out.println("No");
        }
       reader.close();
    }
}


JAVA判断合法标识符

import java.util.*; 

class fun{
    public static boolean isJavaIdentifier(String input)
    {
        if(input!=null && input.length()>0)
        {
            int pos=0;
            if(Character.isJavaIdentifierStart(input.charAt(pos)))
            {
                while(++pos < input.length())
                {
                    if(!Character.isJavaIdentifierPart(input.charAt(pos)))
                    {
                        return false;
                    }
                }
                return true;
            }
        }
        return false;
    }
}
public class Main {  
    public static void main(String[] args) {   
        Scanner cin= new Scanner(System.in);
        while(cin.hasNext())
        {
            fun f = new fun();
            String s;
            s = cin.nextLine();

            boolean x = f. isJavaIdentifier(s);
            System.out.println(x);
//          String s ;  
//            fun f = new fun();  
//            s = cin.nextLine();  
//            boolean x = f. isJavaIdentifier(s);  
//            System.out.println(x);
        }
        cin.close();
    }

}


C语言实验——输入数字星期,输出英文(switch语句)

import java.util.Scanner;

public class Main
{
	
    public static void main(String[] args) 
    {
         Scanner reader = new Scanner(System.in);
        int n=reader.nextInt();
        if(n==1)System.out.println("Monday");
        if(n==2)System.out.println("Tuesday");
        if(n==3)System.out.println("Wednesday");
        if(n==4)System.out.println("Thursday");
        if(n==5)System.out.println("Friday");
        if(n==6)System.out.println("Saturday");
        if(n==7)System.out.println("Sunday");
       reader.close();
    }
}


C语言实验——某年某月的天数

https://blog.csdn.net/Horizonhui/article/details/79598852

你可能感兴趣的:(JAVA,基础)