Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@btfak
Last active December 31, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btfak/7983230 to your computer and use it in GitHub Desktop.
Save btfak/7983230 to your computer and use it in GitHub Desktop.
to peter
import java.util.Scanner;
public class Sort{
private int []letterArray;
private void sortLetter(int length) {
for (int i = 0;i < length-1;i++){
System.out.printf("%d ",letterArray[i]);
letterArray[i] = (letterArray[i] + letterArray[i+1]) % 10;
}
System.out.printf("%d \n",letterArray[length-1]);
if (length == 3 && letterArray[0] == 1 && letterArray[1] ==0 && letterArray[2] == 0){
return;
}else if (length == 2){
return;
}else{
this.sortLetter(length-1);
}
}
private void getInput(){
Scanner scan = new Scanner(System.in);
System.out.print("あなたの名前の文字数は?");
int firstNameLen = scan.nextInt();
System.out.print("相手の名前の文字数は?");
int secondNameLen = scan.nextInt();
this.letterArray = new int[firstNameLen+secondNameLen];
System.out.println("あなたの名前の数値を1つずつ入力してください");
int index = 0;
for(int i = 0;i<this.letterArray.length;i++){
if (i == firstNameLen){
System.out.println("相手の名前の数値を1つずつ入力してください");
index = 0;
}
System.out.print(index+1+"文字目の数値:");
index++;
this.letterArray[i]=scan.nextInt();
}
}
public static void main(String[] args) {
Sort s = new Sort();
s.getInput();
s.sortLetter(s.letterArray.length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment