Skip to content

Instantly share code, notes, and snippets.

@shurain
Created December 9, 2015 06:22
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 shurain/fab2c0209bc313f73be0 to your computer and use it in GitHub Desktop.
Save shurain/fab2c0209bc313f73be0 to your computer and use it in GitHub Desktop.
2004-1 java class
package project2;
import java.io.*;
public class problem2 {
public static void main(String[] args) throws Exception {
int rnum[] = new int[11];
int inum[] = new int[11];
String ist[] = new String[11];
double rd[] = new double[11];
String slts;
int slt = 1;
int pnt = 0;
int ptot = 0;
int dif = 0;
int rec = 0;
BufferedReader kbd = new BufferedReader(new InputStreamReader(System.in));
while(slt == 1){
for(int i=1; i<=10; i++){
rd[i] = Math.random();
System.out.print("Input Number(1-100) : ");
ist[i] = kbd.readLine();
inum[i] = Integer.parseInt(ist[i]);
if(inum[i] > 100 || inum[i] < 0){
break;
}
rnum[i] = (int)(100*99*rd[i])/100 + 1;
dif = inum[i] - rnum[i];
if(dif < 0){
dif = rnum[i] - inum[i];
if(dif <=10){
pnt += 10-dif;
}
else if(dif > 10){
dif = 10;
}
}
else if(dif <=10){
pnt += 10-dif;
}
else if(dif > 10){
dif = 10;
}
System.out.println("Random Number "+i+" is "+rnum[i]);
System.out.println("Input Number "+i+" is "+inum[i]);
System.out.println("At this time, you've got "+(10-dif)+" Point");
}
rec++;
ptot += pnt;
System.out.println("\nTotal Point is "+pnt);
System.out.print("Do you wanna continue? (1.Yes 2.No) : ");
slts = kbd.readLine();
slt = Integer.parseInt(slts);
if(slt == 2){
break;
}
}
System.out.println("You tried it "+rec+" times");
System.out.println("And the Average Point is "+(ptot/rec));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment