本周代码练习

12.6

1.九九乘法口诀表

public class Day05
{
    public static void main(String[] args)
    {
        int i,j;
        for(i=1;i<10;i++)
        {    
            for(j=1;j<=i;j++)
            {
                System.out.print(i+"*"+j+"="+i*j+" ");
            }                
            System.out.println();
        }
    }
}

2.1~100所有素数,每8个换行
public class Day05
{
    public static void main(String[] args)
    {
        int i,j,count=0;
        for(i=2;i<=100;i++)
        {
            boolean isSuShu=true;
            for(j=2;j<i;j++)
            {
                if(i%j==0)
                {
                isSuShu=false;
                break;
                }    
            }
            if(isSuShu)
            {    
            count++;
            System.out.print(i+" ");
            }
            if(count==8)
            {
            System.out.println();
            count=0;
            }
        }
    }    
}

12.8

1.输入单个字符

import java.util.*;
import java.io.*;
public class Day07
{
    public static void main(String[] args)throws IOException
    {
        char c=(char)System.in.read();
        System.out.println(c);
    }
}

2.

public class Day07
{
    public static void main(String[] args)throws IOException
    {
        Scanner cin=new Scanner(System.in);
        int a=cin.nextInt();//输入一个整数
        System.out.println(a);
        double b=cin.nextDouble();//输入一个双精度的浮点数
        System.out.println(b);
        String str=cin.next();//输出一个字符串
        System.out.println(str);
        String str2=cin.nextLine();//输入一行
        System.out.println(str2);
    }
}

3.BufferedReader
public class Day07{
    public static void main(String[] args)throws IOException{
        BufferedReader cin=new BufferedReader(new InputStreamReader(System.in));
        String str=cin.readLine();//输入一行
        System.out.println(str);
        String str2=cin.readLine();
        int a=Integer.parseInt(str2);//将str2转换为int,并复制给a
        System.out.println(a);
        String str3=cin.readLine();
        Double b=Double.parseDouble(str3);//将str3转换为double,并复制给b
        System.out.println(b); 
    }
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值