就你出的题来说,没看懂,就java来说表示起始2,一直到N做循环
import java.util.Scanner;
public class FunNumber {
public static void main(String[] args) {
Scanner fin = new Scanner(System.in);
int N = fin.nextInt();
long i = (long)Math.pow(10, N-1);
long j = (long)Math.pow(10, N);
long count = 0;
for(;i<j;i++){
if(isFun(i,N)) {
count++;
System.out.println(i);
}
}
System.out.println("Count % 1000000007 = " + count%1000000007);
}
public static boolean isFun(long num,int N){
boolean[] num_exist = new boolean[4];
for(;N>0;N--){
int i = (int)(num%Math.pow(10,N)/Math.pow(10,N-1));
switch(i){
case 0:
num_exist[0] = true;
//0必须都在1前
if(num_exist[1]){
return false;
}
break;
case 1:
num_exist[1] = true;
break;
case 2:
num_exist[2] = true;
//2必须都在3前
if(num_exist[3]){
return false;
}
break;
case 3:
num_exist[3] = true;
break;
default:
//不只包含0123
return false;
}
}
//0123至少出现1次
if(num_exist[0]&&num_exist[1]&&num_exist[2]&&num_exist[3]){
return true;
}
return false;
}
}
‘贰’ 一道简单的java编程题
import java.text.ParseException;
import java.text.SimpleDateFormat;
//日期类
public class Date {
private String year;
private String month;
private String day;
public Date(String year, String month, String day) {
this.year = year;
this.month = month;
this.day = day;
}
public void format(){
System.out.println(day + "/" + month + "/" + year);
}
public void calculate(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
try {
java.util.Date startDate = sdf.parse(year + "/" + "01" + "/" + "01");
java.util.Date inputDate = sdf.parse(year + "/" + month + "/" + day);
long resultDay = (inputDate.getTime() - startDate.getTime())/(24 * 1000 * 60 * 60);
System.out.println("第" + (resultDay + 1) + "天");
} catch (ParseException e) {
e.printStackTrace();
}
}
}
//测试类
public class Test {
public static void main(String[] args) {
Date date1 = new Date("2020","04","11");
Date date2 = new Date("2020","01","02");
date1.format();
date1.calculate();
date2.format();
date2.calculate();
}
}
‘叁’ 一道JAVA编程题
class
WangTi2
{
public
static
void
main(String[]
args)
{
long
start
=
System.currentTimeMillis();//看一下要运行多长时间
shuanShu();
long
end
=
System.currentTimeMillis();//看一下要运行多长时间
System.out.println("用时"+(end-start));
}
public
static
void
shuanShu()
{
int[]
arr
=
new
int[100];
arr[0]
=
1;
for(int
x=0;x<11213;x++)
//可以把11213改成100验证方法的正确性
{
//2^20=1048576
int
z
=
0;
/*
这个循环是记录乘2的结果
*/
for(int
y
=0;y<arr.length;y++)
{
arr[y]
=
arr[y]<<1;
arr[y]
=
arr[y]
+
z;
if
(arr[y]>9)
{
arr[y]
-=
10;
if(y!=arr.length-1)
z
=
1;
}
else
z
=
0;
}
}
arr[0]--;
//这个给最后一个位减1,这个值不会是负数。
System.out.println("这个数的最后100位是:");
for(int
x=arr.length-1;x>=0;x--)
{
System.out.print(arr[x]);
if(x%3==0&&x!=0)
System.out.print(",");
}
System.out.println();
}
}
思路是有的。定义数组,只存储最后100位。然后不停的乘2,大于9的向上一个数组加1。重复11213次。再把第一个数组减1。这样做是可以的。效率很低。求高人解答。。呵呵。
‘肆’ 一道有趣的Java编程题,如何输出Hello world!
……v_v……
System.out.append("hello")
==
null
append代表在printStream加上输出。
这回该我的答案该通过了吧?再不通过我就贴到空间上去。
‘伍’ 一道有趣的Java编程题,如何输出Hello world!
可以这样:
publicclassDemo{
publicstaticvoidmain(String...a){
if(newObject(){{System.out.print("Hello,");}}==null){
System.out.print("Hello,");
}else{
System.out.println("World");
}
}
}
输入结果:
‘陆’ 有关java编程题目
按照题目要求编写的圆,圆锥和测试类的Java程序如下
Test.java文件内容如下
class Circle{
private double r;
private String color;
public Circle(double r){
this.r=r;
}
public double area(){
return Math.PI*r*r;
}
public double perimeter(){
return Math.PI*2*r;
}
public double getR(){
return this.r;
}
public void setR(double r){
this.r=r;
}
public String getColor(){
return this.color;
}
public void setColor(String color){
this.color=color;
}
public String toString(){
return "圆的半径为"+r+",颜色为"+color;
}
}
class Cone{
private Circle c;
private double h;
private String color;
public Cone(Circle c,double h){
this.c=c;
this.h=h;
}
public double volume(){
return 1.0/3*c.area()*h;
}
public Circle getCircle(){
return this.c;
}
public void setCircle(Circle c){
this.c=c;
}
public double getH(){
return this.h;
}
public void setH(double h){
this.h=h;
}
public String getColor(){
return this.color;
}
public void setColor(String color){
this.color=color;
}
public String toString(){
return "圆锥的底面积为"+c.area()+",高为"+h+",颜色为"+color;
}
}
public class Test{
public static void main(String[] args){
Circle circle1=new Circle(2.5);
circle1.setColor("红色");
System.out.println(circle1.toString());
System.out.println("圆的面积为"+circle1.area());
System.out.println("圆的周长为"+circle1.perimeter());
Cone circlar1=new Cone(circle1,2.7);
circlar1.setColor("蓝色");
System.out.println(circlar1.toString());
System.out.println("圆锥的体积为"+circlar1.volume());
}
}
‘柒’ JAVA 4道编程题 高分!
//1、2:
public class Student{
//1:创建Student类
char id;//学号
String classes;//班级
String name;//姓名
char gender;//性别
int age;//年龄
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public char getId() {
return id;
}
public String getClasses() {
return classes;
}
public String getName() {
return name;
}
public char getGender() {
return gender;
}
//2.创建Application并实例化Student
public static void main(String[] args){
new Student();
}
}
//3:
public class Student2 {
int age;
String name;
public int getAge() {
return age;
}
public String getName() {
return name;
}
}
class Undergraate extends Student2{
String specialty;
public String getSpecialty() {
return specialty;
}
}
class Postgraate extends Student2{
String studydirection;
public String getStudydirection() {
return studydirection;
}
}
//4:
public class Book {
String name;
String author;
double monthlySale;
public Book(String name, String author, double monthlySale) {
this.name = name;
this.author = author;
this.monthlySale = monthlySale;
}
public Book(){
name="name";
author="author";
monthlySale=0;
}
//这两个成员方法LZ没有说清楚,我猜可能是个意思。
public void setBook(String name, String author, double monthlySale) {
this.name = name;
this.author = author;
this.monthlySale = monthlySale;
}
public void getBook(){
System.out.println("name:"+name);
System.out.println("author:"+author);
System.out.println("monthly sale:"+monthlySale);
}
}
这种题目以后尽量自己做,又不难。
‘捌’ JAVA编程题,知道写的来看看(有点难度)
class ComplexNumber{
private double m_dRealpart;
private double m_dImaginpart;
ComplexNumber(double r,double i){
m_dRealpart=r;
m_dImaginpart=i;
}
void setRealPart(double d){
m_dRealpart=d;
}
void SetImaginpart(double d){
m_dImaginpart=d;
}
ComplexNumber complexAdd(ComplexNumber c){
return new ComplexNumber(m_dRealpart+c.m_dRealpart,m_dImaginpart+c.m_dImaginpart);
}
ComplexNumber complexMinus(ComplexNumber c){
return new ComplexNumber(m_dRealpart-c.m_dRealpart,m_dImaginpart-c.m_dImaginpart);
}
ComplexNumber complexMulti(ComplexNumber c){
return new ComplexNumber(m_dRealpart*c.m_dRealpart-m_dImaginpart*c.m_dImaginpart,m_dImaginpart*c.m_dRealpart+m_dRealpart*c.m_dImaginpart);}
public String toString(){
return m_dRealpart+"+"+m_dImaginpart+"i";
}
}
第二个就不会了;
忘了个括号,抱歉.
1
class Year{
public static void cal(int year){
if(((year%4==0) & (year%100!=0)) | (year%400==0))
System.out.println("是闰年");
else
System.out.println("不是闰年");
}
}
class TestYear{
public static void main(String[] args){
Year.cal(1932);
}
}
2
class TestString{
public static void main(String[] args){
String[] n;
String s="I am good person";
System.out.println("该字符串中字符的个数:"+s.length());
n=s.split(" ",4);
System.out.println("该字符串中单词的个数:"+n.length);
}
}
‘玖’ 5道简单的JAVA编程题(高分悬赏)
很详细的帮你写下,呵呵,所以要给分哦!
1、
(1)源程序如下:
public class One {
public static void main(String[] args) {
String name = "张三";
int age = 23;
char sex = '男';
String myclass = "某某专业2班";
System.out.println("姓名:" + name);
System.out.println("姓名:" + age);
System.out.println("姓名:" + sex);
System.out.println("姓名:" + myclass);
}
}
(2)
编写完程序的后缀名是.java,如本题,文件名就是One.java。
开始\运行\cmd,进入“命令提示符窗口”,然后用javac编译器编译.java文件,语句:javac One.java。
(3)
编译成功后,生成的文件名后缀是.class,叫做字节码文件。再用java解释器来运行改程序,语句:java One
2、编写程序,输出1到100间的所有偶数
(1)for语句
public class Two1 {
public static void main(String[] args) {
for(int i=2;i<=100;i+=2)
System.out.println(i);
}
}
(2)while语句
public class Two2 {
public static void main(String[] args) {
int i = 2;
while (i <= 100) {
System.out.println(i);
i += 2;
}
}
}
(3)do…while语句
public class Two3 {
public static void main(String[] args) {
int i = 2;
do {
System.out.println(i);
i += 2;
}while(i<=100);
}
}
3、编写程序,从10个数当中找出最大值。
(1)for循环
import java.util.*;
public class Three1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
for (int i = 0; i < 10; i++) {
System.out.print("输入第" + (i + 1) + "个数:");
number = input.nextInt();
if (max < number)
max = number;
}
System.out.println("最大值:" + max);
}
}
(2)while语句
import java.util.*;
public class Three2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
int i = 0;
while (i < 10) {
System.out.print("输入第" + (i + 1) + "个数:");
number = input.nextInt();
if (max < number)
max = number;
i++;
}
System.out.println("最大值:" + max);
}
}
(3)do…while语句
import java.util.*;
public class Three3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
int i = 0;
do {
System.out.print("输入第" + (i + 1) + "个数:");
number = input.nextInt();
if (max < number)
max = number;
i++;
}while(i<10);
System.out.println("最大值:" + max);
}
}
4、编写程序,计算从1到100之间的奇数之和。
(1)for循环
public class Four1 {
public static void main(String[] args) {
int sum=0;
for(int i = 1;i<=100;i+=2){
sum+=i;
}
System.out.println("1~100间奇数和:" + sum);
}
}
(2)while语句
public class Four2 {
public static void main(String[] args) {
int sum = 0;
int i = 1;
while (i <= 100) {
sum += i;
i += 2;
}
System.out.println("1~100间奇数和:" + sum);
}
}
(3)do…while语句
public class Four3 {
public static void main(String[] args) {
int sum = 0;
int i = 1;
do {
sum += i;
i += 2;
} while (i <= 100);
System.out.println("1~100间奇数和:" + sum);
}
}
5、
(1)什么是类的继承?什么是父类?什么是子类?举例说明。
继承:是面向对象软件技术当中的一个概念。如果一个类A继承自另一个类B,就把这个A称为"B的子类",而把B称为"A的父类"。继承可以使得子类具有父类的各种属性和方法,而不需要再次编写相同的代码。在令子类继承父类的同时,可以重新定义某些属性,并重写某些方法,即覆盖父类的原有属性和方法,使其获得与父类不同的功能。另外,为子类追加新的属性和方法也是常见的做法。继承需要关键字extends。举例:
class A{}
class B extends A{}
//成员我就不写了,本例中,A是父类,B是子类。
(2)编写一个继承的程序。
class Person {
public String name;
public int age;
public char sex;
public Person(String n, int a, char s) {
name = n;
age = a;
sex = s;
}
public void output1() {
System.out.println("姓名:" + name + "\n年龄:" + age + "\n性别:" + sex);
}
}
class StudentPerson extends Person {
String school, department, subject, myclass;
public StudentPerson(String sc, String d, String su, String m, String n,
int a, char s) {
super(n, a, s);
school = sc;
department = d;
subject = su;
myclass = m;
}
public void output2() {
super.output1();
System.out.println("学校:" + school + "\n系别:" + department + "\n专业:"
+ subject + "\n班级:" + myclass);
}
}
public class Five2 {
public static void main(String[] args) {
StudentPerson StudentPersonDemo = new StudentPerson("某某大学", "某某系别",
" 某专业", "某某班级", " 张三", 23, '男');
StudentPersonDemo.output2();
}
}