Javaコンピュータの2級(上機の本当の問題)
7449 ワード
1.
import java.io.*;
public class Java_1 {
public static void main(String[ ] args) throws IOException {
InputStreamReader ir;
BufferedReader in;
int max, x;
String data;
max = 0;
ir = new InputStreamReader(System.in);
in = new BufferedReader(ir);
System.out.println(" 5 :");
//*********Found**********
for (int i = 1; i<= 5; i++) {
data = in.readLine();
//*********Found**********
x = Integer.parseInt(data);
if ( max < x )
//*********Found**********
max = x;
}
System.out.println(" "+ max);
}
}
2.
import java.io.File;
public class Java_2
{
public static void main(String s[])
{
//Getting the Current Working Directory
String curDir = System.getProperty("user.dir");
System.out.println(" :"+curDir);
//*********Found**********
File ff=new File(curDir);
String[] files=ff.list();
for(int i=0; i");
String[] files=f.list();
level++;
//*********Found**********
for(int i=0; i best)
best = scores[i];
}
//
for (int i=0; i= best - 10)
grade = 'A';
//*********Found**********
else if (scores[i] >= best - 20)
grade = 'B';
else if (scores[i] >= best - 30)
grade = 'C';
else if (scores[i] >= best - 40)
grade = 'D';
else
grade = 'F';
System.out.println("Student " + i + " score is " + scores[i] +
" and grade is " + grade);
}
}
}
2.
public class Java_2 {
public static void main(String[ ] args) {
Point pt;
//*********Found**********
pt = new Point(2, 3);
System.out.println(pt);
}
}
class Point {
//*********Found**********
private int x;
private int y;
//*********Found**********
public Point (int a, int b) {
x = a;
y = b;
}
int getX( ) {
return x;
}
int getY( ) {
return y;
}
void setX(int a) {
x = a;
}
void setY(int b) {
y = b;
}
//*********Found**********
public String toString ( ) {
return "( " + x + "," + y + " ) ";
}
}
3.
import java.awt.*;
import java.awt.event.*;
//*********Found**********
import javax.swing.*;
//*********Found**********
public class Java_3 extends JPanel{
private int counter = 0;
private JButton closeAllButton;
public Java_3() {
JButton newButton = new JButton("New");
//*********Found**********
add(newButton);
newButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
CloseFrame f = new CloseFrame();
counter++;
f.setTitle(" " + counter);
f.setSize(200, 150);
f.setLocation(30 * counter, 30 * counter);
//*********Found**********
f.setVisible(true);
closeAllButton.addActionListener(f);
}
});
closeAllButton = new JButton("Close all");
add(closeAllButton);
}
public static void main(String[ ] args) {
JFrame frame = new JFrame();
frame.setTitle(" ");
frame.setSize(300, 200);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Container contentPane = frame.getContentPane();
contentPane.add(new Java_3());
frame.setVisible(true) ;
}
}
//*********Found**********
class CloseFrame extends JFrame implements ActionListener {
public void actionPerformed(ActionEvent evt) {
setVisible(false);
}
}
1.
public class Java_1 {
public static void main(String args[]) {
int a[][] = {{2, 3, 4}, {4, 6, 5}};
int b[][] = {{1, 5, 2, 8}, {5, 9, 10, -3}, {2, 7, -5, -18}};
int c[][] = new int[2][4];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 4; j++) {
//*********Found********
c[i][j] = 0 ;
//*********Found********
for (int k = 0; k < 3; k++)
//*********Found********
c[i][j] += a[i][k]*b[k][j];
System.out.print(c[i][j] + " ");
}
System.out.println();
}
}
}