62,614
社区成员
发帖
与我相关
我的任务
分享
import java.util.Scanner;
public class CSDNDemo {
private static int index=0;
private static int m[]=new int[3];
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n1=sc.nextInt();
fun(n1);
int n2=sc.nextInt();
fun(n2);
int n3=sc.nextInt();
fun(n3);
for(int x=0;x<m.length;x++){
System.out.println(m[x]);
}
sc.close();
}
public static void fun(int n){
if(n%8>5){
m[index]=10-(n%8);
}else if(n%8==0){
m[index]=2;
}else{
m[index]=n%8;
}
index++;
}
}
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while(input.hasNext()) {
int number = input.nextInt();
int status = 1;
int flag = 1;
for(int i = 1; i < number; i++) {
status += flag;
if(status == 5 || status == 1){
flag = -flag;
}
}
System.out.println(status);
}
}
}
import java.util.Scanner;
public class Test4 {
/**
* 小女孩数数问题
* @param args
*/
public static void main(String[] args) {
int x;
int result=0;
Boolean flag1=false;
Boolean flag2=false;
int [] results = new int [3];
int count = 0;
while(count<3) {
Scanner sc = new Scanner(System.in);
while(true) {
x = sc.nextInt();
if(x>0)
break;
System.out.println("输入有误,请重新输入!");
}
for(int i=1; i<=x; i++) {
if(result <= 1)
flag1 = true;
else if(result == 5)
flag2 = true;
if(result < 5 && flag1) {
flag2 = false;
result ++;
continue;
}
else if(result > 1 && flag2) {
flag1 = false;
result --;
continue;
}
}
results[count] = result;
result = 0;
count ++;
}
for(int i=0; i<3; i++) {
System.out.println(results[i]);
}
}
}
模拟了数数过程,只是时间复杂度略大import java.util.Scanner;
public class CSDNDemo {
private static int index=0;
private static int m[]=new int[3];
public static void main(String[] args) {
System.out.println(1000000001%8);
Scanner sc=new Scanner(System.in);
int n1=sc.nextInt();
fun(n1);
int n2=sc.nextInt();
fun(n2);
int n3=sc.nextInt();
fun(n3);
for(int x=0;x<m.length;x++){
System.out.println(m[x]);
}
sc.close();
}
public static void fun(int n){
if(n<=5){
m[index]=n;
}else{
if(n%8>5){
m[index]=10-(n%8);
}else if(n%8==0){
m[index]=2;
}else{
m[index]=n%8;
}
}
index++;
}
}
刚才网不好,我看到的代码是这样,现在看的不一样了,我再看看啊