使用控制语句和预定义方法的一个给定数字 [英] One To Given Number With Out Using Control Statements And Predefined Methods
本文介绍了使用控制语句和预定义方法的一个给定数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用控制语句打印一个给定的数字。不使用预定义的方法
解决方案
如果你想打印任何东西 - 无论是一张纸或一个屏幕 - 您必须使用至少一种预定义的方法。另一种方法是从头开始编写整个操作系统,这在像这样的小文本框中是不实用的。
在C到控制台,它很容易:
int i;
int maxnumber = 10 ;
for (i = 1 ; i< = maxnumber; i ++)
{
printf( %d \ n,i);
}其他系统或语言可能需要更多工作。
< pre lang =cs> no,控制语句表示循环, if 语句, break ,继续,返回语句
out 使用这些我希望得到的结果
OK:
printf( %d \ n, 1 );
printf( %d \ n, 2 跨度>);
printf( %d \ n, 3 跨度>);
printf( %d \ n, 4 跨度>);
printf( %d \ n, 5 跨度>);
printf( %d \ n, 6 跨度>);
printf( %d \ n, 7 跨度>);
printf( %d \ n, 8 跨度>);
printf( %d \ n, 9 跨度>);
printf( %d \ n, 10 );
如果没有某种形式的控制语句,您无法做出决定:您所能做的就是编写代码从开始到结束都没有分支,测试或循环 - 除非你接受无限循环。即便是 ? operator是if控制语句的简短形式。
你可能想要获得一个战利品:http://stackoverflow.com/questions/4568645/printing-1-to-1000-without-loop-or-conditionals [ ^ ]
既不是C也不是Java,它是C ++。循环中的答案不使用任何循环或条件。
class Main {
int i = 1 ;
public static 布尔打印( int max){
System.out.print(i)
i ++;
boolean j =(i< = max)&& print(max);
return j;
}
public static void main( String [] args){
System.out.println( 输入数字);
扫描仪扫描仪= 新扫描仪(系统。 in );
int max = scanner.nextInt();
print(max);
}
How to print the one to given number.with out using control statements and without using predefined methods
解决方案
If you want to print anything - be it on a piece of paper or a screen - you have to use at least one predefined method. The alternative is to write the whole operating system from scratch and that just isn't practical in a little textbox like this one.
In C to a console, it's easy:
int i; int maxnumber = 10; for (i = 1; i <= maxnumber; i++) { printf("%d\n", i); }Other systems or languages may require more work.
"no,control statements means loops,if statements,break,continue,return statements with out using these things i want the result
"
OK:
printf("%d\n", 1); printf("%d\n", 2); printf("%d\n", 3); printf("%d\n", 4); printf("%d\n", 5); printf("%d\n", 6); printf("%d\n", 7); printf("%d\n", 8); printf("%d\n", 9); printf("%d\n", 10);
You cannot make decisions without control statements of some form: all you can do is write code that runs from the start to the end with no branches, tests or loops - unless you accept an infinite loop. Even the "?" operator is a short form for an "if" control statement.
You might want to have a loot at this : http://stackoverflow.com/questions/4568645/printing-1-to-1000-without-loop-or-conditionals[^]
It's neither C nor Java, it's C++. The answer in the loop does not use any loop or condition.
class Main{ int i=1; public static boolean print(int max){ System.out.print(i) i++; boolean j=(i<=max)&&print(max); return j; } public static void main(String[] args){ System.out.println("enter the number"); Scanner scanner=new Scanner(System.in); int max=scanner.nextInt(); print(max); }
这篇关于使用控制语句和预定义方法的一个给定数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文