怎么做这个java?

编程入门 行业动态 更新时间:2024-10-24 12:34:09
本文介绍了怎么做这个java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

问题:写一个Java程序列出1000到9999之间存在的所有可能的偶数,并且每个偶数中的数字不会重复。 输出样本: - 即使没有重复数字的清单 1024 1026 1028 1032 1034 1036 1038 1042 ... ... ... 9874 9876 要求: - i)编码 ii)评论 iii)对象的实施 - 导向概念 我尝试过: 我试过做数字在1000到9999之间,但是该出口的数字保持重复数字,如1013,数字1在这里重复两次。

解决方案

这是你的作业,所以我不会给你任何代码。 但是......这很简单。 写一个接受一个整数的函数,并根据所有数字唯一?返回一个真/假结果。 有几种方法可以做到这一点,但最简单的方法是设置一个数组十个布尔值,并将它们预置为假。 然后在大于零的情况下循环输入数字并在旁边循环: 1)获得最低值数字起诉模数运算符。 2)检查该数字索引处的数组元素。因此,如果数字为0,则使用数组[0]。如果是1,则使用数组[1],......等等。如果该索引处的数组元素为true,则已经找到该数字,因此您可以返回false - 这有重复的数字。 3)否则,将索引处的数组元素设置为true。 4)将输入数除以10然后再转一圈。 如果由于输入变为零而退出循环,则返回true - 没有重复。

Question: Write a Java program to list out all possible even numbers that exists in between 1000 to 9999 and the digits exit in each of the even numbers shall not be repeated. Sample of output:- List of even without repeated digit 1024 1026 1028 1032 1034 1036 1038 1042 ... ... ... 9874 9876 Requirement:- i)Coding ii)Comments iii)Implementation of object-oriented concept What I have tried: I have tried to do the numbers between 1000 to 9999 but the digit the that exit keep repeat the number like 1013 ,the number of "1" is repeated twice in here.

解决方案

This is your homework, so I'll give you no code. But...it's pretty simple. Write a function that accepts an integer number, and returns a true / false result based on "are all digits unique?" There are a few ways to do this, but the easiest is to set up an array of ten booleans, and preset each of them to false. Then loop through the input number while it is greater than zero and in side teh loop: 1) Get the lowest digit suing the modulus operator. 2) Check the array element at that digit index. So if the digit is 0, use array[0]. If it's 1, use array[1], ... and so forth. If the array element at that index is true, the digit has been found already and so you can return false - this has repeated digits. 3) Otherwise, set the array element at the index to true. 4) Divide the input number by 10 and go round again. If you exit the loop because the input became zero, return true - there are no repeats.

更多推荐

怎么做这个java?

本文发布于:2023-10-26 09:35:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529777.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:怎么做   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!