標題:
310-迴圈正偶數相加
[打印本頁]
作者:
許承鴻
時間:
2018-7-24 18:24
標題:
310-迴圈正偶數相加
import java.util.Scanner;
public class JPD03 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
}
}
作者:
張閎鈞
時間:
2018-7-24 19:48
package HI87;
import java.util.Scanner;
public class hi78 {
static Scanner keyboard = new Scanner(System.in);
public static void main (String argv[]){
int i=0;
int k=0;
do
{
System.out.print("請輸入n的職<n >0,且為偶數>:");
k=keyboard.nextInt();
}while(k%2!=0);
System.out.print("2+4+...+"+k+"="+((2+k)*(k/2)/2));
}
}
複製代碼
作者:
張閎鈞
時間:
2018-7-24 19:59
package HI87;
import java.util.Scanner;
public class hi78 {
static Scanner keyboard = new Scanner(System.in);
public static void main (String argv[]){
int i=0;
int k=0;
do
{
System.out.print("請輸入n的職<n >0,且為偶數>:");
k=keyboard.nextInt();
}while(k%2!=0||k<0);
System.out.print("2+4+...+"+k+"="+((2+k)*(k/2)/2));
}
}
複製代碼
作者:
巫沛庭
時間:
2018-7-24 20:08
import java.util.Scanner;
public class JPA03 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
int num,num1=0;
do{
System.out.print("請輸入n的值(n>0,且為偶數)");
num=keyboard.nextInt();
}while(num<0 || num%2!=0);
for(int i=2;i<=num;i=i+2)
{
num1+=i;
}
System.out.print(num1);
}
}
複製代碼
作者:
巫晉宇
時間:
2018-7-24 20:15
package sdasda;
import java.util.Scanner;
public class dwaadw {
static Scanner e=new Scanner(System.in);
public static void main(String[] args) {
int t = 0,i=0;
int o;
do
{
o=e.nextInt();
}while(o%2!=0 || o<0);
for(i=2;i<=o;i=i+2)
{
t+=i;
}
System.out.println("2+4+....."+o+"="+t);
}
}
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2