这几天写的几个小程序
来源:互联网 发布:老电视能看网络电视吗 编辑:程序博客网 时间:2024/04/30 01:12
在网上找了几个小练习题做了做,回顾回顾基础
/**
小明在一张纸上写了一个四位数3_45(其中_代表一个看不清的数字)。已知这个四位数被3除后值为1115,编程求出_
*/
class ti1
{
public static void main(String[] args)
{
int a = 1115*3;
int _ = a%1000/100;
System.out.println(_);
}
}
/**
学校买来100张电影票,花了580元,票价有5元、6元。编写程序算出两种电影票各有多少张?
*/
class ti3
{
public static void main(String[] args)
{
int piaoa=0;
int piaob=100;
while(true)
{
if(piaoa*5+piaob*6 == 580)
{
System.out.println("最终答案是:piaoa="+piaoa+";"+"piaob="+piaob);
break;
}
else
{
piaoa++;
piaob=100-piaoa;
}
System.out.println("piaoa="+piaoa+";"+"piaob="+piaob);
}
}
}
/**
小林对小明说:“只要把你的日子乘以12,再把出生的月份乘以31,
然后把他们加起来,将总数告诉我。我能马上告诉你的生日是几月几日。
”小明随口说出302,小林在计算机上编了一个简单的程序,马上就算出小明的生日是2月20日。
小林的程序是怎样编的?
*/
class ti4
{
public static void main(String[] args)
{
int month;
int day;
//String totalCountString = args[0];
//int totalCount=Integer.valueOf(totalCount);
int totalCount=302;
for(month=1;month<=12;month++)
{
for(day=1;day<=31;day++)
{
if(totalCount == day*12+month*31)
{
System.out.println("最终答案:month="+month+"day="+day);
break; //怎样同时跳出两层循环
}
System.out.println("month="+month+"day="+day);
}
if(totalCount == day*12+month*31)
{
System.out.println("最终答案:month="+month+"day="+day);
break;
}
}
}
}
/**
求s=a+aa+aaa+aaaa+aaaaa的值,其中a是一个数字
*/
import java.lang.Math.*;
import java.util.*;
class ti5
{
public static void main(String[] args)
{
Scanner can=new Scanner(System.in);
int totalcount=can.nextInt(); //参加计算的数个数
int a=1;
int s=0;
for(int count=0;count<totalcount;count++)
{
int tempcount=count;
while(tempcount>=0)
{
s+=a*Math.pow(10,tempcount);
tempcount--;
}
}
System.out.println(s);
}
}
- 这几天写的几个小程序
- 这几天写了一个小程序后的感想
- 这几天写了个小程序,期间碰到的问题,现已解决
- 这几天学习regexp写的小例子
- 这几天写的一个wxWidgets的程序。。。。。
- 写了几个有关operaminimod的python小程序
- 使用python写程序时遇到的几个小问题
- 初学51单片,写的几个小程序
- C#几个小程序(convert转换,几周几天,几天几时几分几秒,闰年)
- 这几天用com写个程序
- 写的几个小玩意
- 这几天的程序心得
- io的几个小程序
- Python的几个小程序
- 几个有意思的小程序
- scala的几个小程序
- 几个基础的小程序
- 这几天写java遇到的问题
- HDU4405 Aeroplane chess
- Java学习(回顾)笔记之day4
- 这几天心里颇不宁静
- PHP 分页类
- C++ 特殊机制收集
- 这几天写的几个小程序
- hibernate:1+N问题
- sizeof作用在struct和union上的情况,经典解答
- com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:的解决
- 史上最著名的10个思想实验
- sha1哈希算法 分组过程以及算法路程详细
- Java浅复制和深复制
- 根据上排的数填写下排的数,并满足要求
- C# 中文转拼音方法